../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
465 / 474
98.1%
Branches:
309 / 328
94.2%
Functions:
29 / 29
100.0%

libavcodec/vvc/intra.c
Line Branch Exec Source
1 /*
2 * VVC intra prediction
3 *
4 * Copyright (C) 2021 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 #include "libavutil/frame.h"
23 #include "libavutil/imgutils.h"
24
25 #include "data.h"
26 #include "inter.h"
27 #include "intra.h"
28 #include "itx_1d.h"
29
30 #define POS(c_idx, x, y) \
31 &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
32 (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
33
34 589076 static int is_cclm(enum IntraPredMode mode)
35 {
36
6/6
✓ Branch 2 → 3 taken 522685 times.
✓ Branch 2 → 5 taken 66391 times.
✓ Branch 3 → 4 taken 497983 times.
✓ Branch 3 → 5 taken 24702 times.
✓ Branch 4 → 5 taken 27697 times.
✓ Branch 4 → 6 taken 470286 times.
589076 return mode == INTRA_LT_CCLM || mode == INTRA_L_CCLM || mode == INTRA_T_CCLM;
37 }
38
39 175544 static int derive_ilfnst_pred_mode_intra(const VVCLocalContext *lc, const TransformBlock *tb)
40 {
41 175544 const VVCFrameContext *fc = lc->fc;
42 175544 const VVCSPS *sps = fc->ps.sps;
43 175544 const CodingUnit *cu = lc->cu;
44 175544 const int x_tb = tb->x0 >> fc->ps.sps->min_cb_log2_size_y;
45 175544 const int y_tb = tb->y0 >> fc->ps.sps->min_cb_log2_size_y;
46 175544 const int x_c = (tb->x0 + (tb->tb_width << sps->hshift[1] >> 1) ) >> fc->ps.sps->min_cb_log2_size_y;
47 175544 const int y_c = (tb->y0 + (tb->tb_height << sps->vshift[1] >> 1)) >> fc->ps.sps->min_cb_log2_size_y;
48 175544 const int min_cb_width = fc->ps.pps->min_cb_width;
49 175544 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_tb, y_tb);
50
2/2
✓ Branch 2 → 3 taken 123501 times.
✓ Branch 2 → 4 taken 52043 times.
175544 int pred_mode_intra = tb->c_idx == 0 ? cu->intra_pred_mode_y : cu->intra_pred_mode_c;
51
4/4
✓ Branch 5 → 6 taken 20026 times.
✓ Branch 5 → 8 taken 155518 times.
✓ Branch 6 → 7 taken 5109 times.
✓ Branch 6 → 8 taken 14917 times.
175544 if (intra_mip_flag && !tb->c_idx) {
52 5109 pred_mode_intra = INTRA_PLANAR;
53
2/2
✓ Branch 9 → 10 taken 16549 times.
✓ Branch 9 → 16 taken 153886 times.
170435 } else if (is_cclm(pred_mode_intra)) {
54 16549 int intra_mip_flag_c = SAMPLE_CTB(fc->tab.imf, x_c, y_c);
55 16549 int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_c, y_c);
56
2/2
✓ Branch 10 → 11 taken 4523 times.
✓ Branch 10 → 12 taken 12026 times.
16549 if (intra_mip_flag_c) {
57 4523 pred_mode_intra = INTRA_PLANAR;
58
4/4
✓ Branch 12 → 13 taken 10642 times.
✓ Branch 12 → 14 taken 1384 times.
✓ Branch 13 → 14 taken 44 times.
✓ Branch 13 → 15 taken 10598 times.
12026 } else if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT) {
59 1428 pred_mode_intra = INTRA_DC;
60 } else {
61 10598 pred_mode_intra = SAMPLE_CTB(fc->tab.ipm, x_c, y_c);
62 }
63 }
64 175544 pred_mode_intra = ff_vvc_wide_angle_mode_mapping(cu, tb->tb_width, tb->tb_height, tb->c_idx, pred_mode_intra);
65
66 175544 return pred_mode_intra;
67 }
68
69 //8.7.4 Transformation process for scaled transform coefficients
70 175544 static void ilfnst_transform(const VVCLocalContext *lc, TransformBlock *tb)
71 {
72 175544 const VVCSPS *sps = lc->fc->ps.sps;
73 175544 const CodingUnit *cu = lc->cu;
74 175544 const int w = tb->tb_width;
75 175544 const int h = tb->tb_height;
76
4/4
✓ Branch 2 → 3 taken 101394 times.
✓ Branch 2 → 5 taken 74150 times.
✓ Branch 3 → 4 taken 69150 times.
✓ Branch 3 → 5 taken 32244 times.
175544 const int n_lfnst_out_size = (w >= 8 && h >= 8) ? 48 : 16; ///< nLfnstOutSize
77
4/4
✓ Branch 6 → 7 taken 101394 times.
✓ Branch 6 → 9 taken 74150 times.
✓ Branch 7 → 8 taken 69150 times.
✓ Branch 7 → 9 taken 32244 times.
175544 const int log2_lfnst_size = (w >= 8 && h >= 8) ? 3 : 2; ///< log2LfnstSize
78 175544 const int n_lfnst_size = 1 << log2_lfnst_size; ///< nLfnstSize
79
8/8
✓ Branch 10 → 11 taken 40673 times.
✓ Branch 10 → 12 taken 134871 times.
✓ Branch 11 → 12 taken 27977 times.
✓ Branch 11 → 14 taken 12696 times.
✓ Branch 12 → 13 taken 74150 times.
✓ Branch 12 → 15 taken 88698 times.
✓ Branch 13 → 14 taken 50407 times.
✓ Branch 13 → 15 taken 23743 times.
175544 const int non_zero_size = ((w == 8 && h == 8) || (w == 4 && h == 4)) ? 8 : 16; ///< nonZeroSize
80 175544 const int pred_mode_intra = derive_ilfnst_pred_mode_intra(lc, tb);
81 175544 const int transpose = pred_mode_intra > 34;
82 int u[16], v[48];
83
84
2/2
✓ Branch 19 → 18 taken 2303880 times.
✓ Branch 19 → 20 taken 175544 times.
2479424 for (int x = 0; x < non_zero_size; x++) {
85 2303880 int xc = ff_vvc_diag_scan_x[2][2][x];
86 2303880 int yc = ff_vvc_diag_scan_y[2][2][x];
87 2303880 u[x] = tb->coeffs[w * yc + xc];
88 }
89 175544 ff_vvc_inv_lfnst_1d(v, u, non_zero_size, n_lfnst_out_size, pred_mode_intra,
90 175544 cu->lfnst_idx, sps->log2_transform_range);
91
2/2
✓ Branch 21 → 22 taken 50894 times.
✓ Branch 21 → 31 taken 124650 times.
175544 if (transpose) {
92 50894 int *dst = tb->coeffs;
93 50894 const int *src = v;
94
2/2
✓ Branch 22 → 23 taken 35550 times.
✓ Branch 22 → 26 taken 15344 times.
50894 if (n_lfnst_size == 4) {
95
2/2
✓ Branch 25 → 24 taken 142200 times.
✓ Branch 25 → 37 taken 35550 times.
177750 for (int y = 0; y < 4; y++) {
96 142200 dst[0] = src[0];
97 142200 dst[1] = src[4];
98 142200 dst[2] = src[8];
99 142200 dst[3] = src[12];
100 142200 src++;
101 142200 dst += w;
102 }
103 } else {
104
2/2
✓ Branch 30 → 27 taken 122752 times.
✓ Branch 30 → 37 taken 15344 times.
138096 for (int y = 0; y < 8; y++) {
105 122752 dst[0] = src[0];
106 122752 dst[1] = src[8];
107 122752 dst[2] = src[16];
108 122752 dst[3] = src[24];
109
2/2
✓ Branch 27 → 28 taken 61376 times.
✓ Branch 27 → 29 taken 61376 times.
122752 if (y < 4) {
110 61376 dst[4] = src[32];
111 61376 dst[5] = src[36];
112 61376 dst[6] = src[40];
113 61376 dst[7] = src[44];
114 }
115 122752 src++;
116 122752 dst += w;
117 }
118 }
119
120 } else {
121 124650 int *dst = tb->coeffs;
122 124650 const int *src = v;
123
2/2
✓ Branch 36 → 32 taken 713824 times.
✓ Branch 36 → 37 taken 124650 times.
838474 for (int y = 0; y < n_lfnst_size; y++) {
124
2/2
✓ Branch 32 → 33 taken 498600 times.
✓ Branch 32 → 34 taken 215224 times.
713824 int size = (y < 4) ? n_lfnst_size : 4;
125 713824 memcpy(dst, src, size * sizeof(int));
126 713824 src += size;
127 713824 dst += w;
128 }
129 }
130 175544 tb->max_scan_x = n_lfnst_size - 1;
131 175544 tb->max_scan_y = n_lfnst_size - 1;
132 175544 }
133
134 //part of 8.7.4 Transformation process for scaled transform coefficients
135 1158616 static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalContext *lc, const TransformBlock *tb, enum VVCTxType *trh, enum VVCTxType *trv)
136 {
137 1158616 const CodingUnit *cu = lc->cu;
138 static const enum VVCTxType mts_to_trh[] = { VVC_DCT2, VVC_DST7, VVC_DCT8, VVC_DST7, VVC_DCT8 };
139 static const enum VVCTxType mts_to_trv[] = { VVC_DCT2, VVC_DST7, VVC_DST7, VVC_DCT8, VVC_DCT8 };
140 1158616 const VVCSPS *sps = fc->ps.sps;
141 1158616 int implicit_mts_enabled = 0;
142
6/6
✓ Branch 2 → 3 taken 834498 times.
✓ Branch 2 → 5 taken 324118 times.
✓ Branch 3 → 4 taken 143243 times.
✓ Branch 3 → 6 taken 691255 times.
✓ Branch 4 → 5 taken 32899 times.
✓ Branch 4 → 6 taken 110344 times.
1158616 if (tb->c_idx || (cu->isp_split_type != ISP_NO_SPLIT && cu->lfnst_idx)) {
143 357017 *trh = *trv = VVC_DCT2;
144 357017 return;
145 }
146
147
2/2
✓ Branch 6 → 7 taken 657995 times.
✓ Branch 6 → 15 taken 143604 times.
801599 if (sps->r->sps_mts_enabled_flag) {
148
2/2
✓ Branch 7 → 8 taken 547651 times.
✓ Branch 7 → 14 taken 110344 times.
657995 if (cu->isp_split_type != ISP_NO_SPLIT ||
149
4/4
✓ Branch 8 → 9 taken 34957 times.
✓ Branch 8 → 10 taken 512694 times.
✓ Branch 9 → 10 taken 523 times.
✓ Branch 9 → 14 taken 34434 times.
547651 (cu->sbt_flag && FFMAX(tb->tb_width, tb->tb_height) <= 32) ||
150
4/4
✓ Branch 10 → 11 taken 45019 times.
✓ Branch 10 → 15 taken 468198 times.
✓ Branch 11 → 12 taken 28412 times.
✓ Branch 11 → 15 taken 16607 times.
513217 (!sps->r->sps_explicit_mts_intra_enabled_flag && cu->pred_mode == MODE_INTRA &&
151
4/4
✓ Branch 12 → 13 taken 18449 times.
✓ Branch 12 → 15 taken 9963 times.
✓ Branch 13 → 14 taken 14592 times.
✓ Branch 13 → 15 taken 3857 times.
28412 !cu->lfnst_idx && !cu->intra_mip_flag)) {
152 159370 implicit_mts_enabled = 1;
153 }
154 }
155
2/2
✓ Branch 15 → 16 taken 159370 times.
✓ Branch 15 → 36 taken 642229 times.
801599 if (implicit_mts_enabled) {
156 159370 const int w = tb->tb_width;
157 159370 const int h = tb->tb_height;
158
2/2
✓ Branch 16 → 17 taken 34434 times.
✓ Branch 16 → 26 taken 124936 times.
159370 if (cu->sbt_flag) {
159
4/4
✓ Branch 17 → 18 taken 18255 times.
✓ Branch 17 → 19 taken 16179 times.
✓ Branch 18 → 19 taken 8587 times.
✓ Branch 18 → 20 taken 9668 times.
34434 *trh = (cu->sbt_horizontal_flag || cu->sbt_pos_flag) ? VVC_DST7 : VVC_DCT8;
160
4/4
✓ Branch 21 → 22 taken 16179 times.
✓ Branch 21 → 23 taken 18255 times.
✓ Branch 22 → 23 taken 7800 times.
✓ Branch 22 → 24 taken 8379 times.
34434 *trv = (!cu->sbt_horizontal_flag || cu->sbt_pos_flag) ? VVC_DST7 : VVC_DCT8;
161 } else {
162
4/4
✓ Branch 26 → 27 taken 105634 times.
✓ Branch 26 → 29 taken 19302 times.
✓ Branch 27 → 28 taken 85366 times.
✓ Branch 27 → 29 taken 20268 times.
124936 *trh = (w >= 4 && w <= 16) ? VVC_DST7 : VVC_DCT2;
163
4/4
✓ Branch 30 → 31 taken 79098 times.
✓ Branch 30 → 33 taken 45838 times.
✓ Branch 31 → 32 taken 76026 times.
✓ Branch 31 → 33 taken 3072 times.
124936 *trv = (h >= 4 && h <= 16) ? VVC_DST7 : VVC_DCT2;
164 }
165 159370 return;
166 }
167 642229 *trh = mts_to_trh[cu->mts_idx];
168 642229 *trv = mts_to_trv[cu->mts_idx];
169 }
170
171 2736424 static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)
172 {
173 2736424 const VVCSPS *sps = lc->fc->ps.sps;
174 2736424 const int hs = sps->hshift[ch_type];
175 2736424 const int vs = sps->vshift[ch_type];
176 ReconstructedArea *a;
177
178
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2736424 times.
2736424 if (lc->num_ras[ch_type] >= FF_ARRAY_ELEMS(lc->ras[ch_type]))
179 ✗ return AVERROR_INVALIDDATA;
180
181 2736424 a = &lc->ras[ch_type][lc->num_ras[ch_type]];
182 2736424 a->x = x0 >> hs;
183 2736424 a->y = y0 >> vs;
184 2736424 a->w = w >> hs;
185 2736424 a->h = h >> vs;
186 2736424 lc->num_ras[ch_type]++;
187
188 2736424 return 0;
189 }
190
191 1445490 static void add_tu_area(const TransformUnit *tu, int *x0, int *y0, int *w, int *h)
192 {
193 1445490 *x0 = tu->x0;
194 1445490 *y0 = tu->y0;
195 1445490 *w = tu->width;
196 1445490 *h = tu->height;
197 1445490 }
198
199 #define MIN_ISP_PRED_WIDTH 4
200 1032766 static int get_luma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
201 {
202 1032766 int has_luma = 1;
203 1032766 add_tu_area(tu, x0, y0, w, h);
204
4/4
✓ Branch 3 → 4 taken 77382 times.
✓ Branch 3 → 6 taken 955384 times.
✓ Branch 4 → 5 taken 28178 times.
✓ Branch 4 → 6 taken 49204 times.
1032766 if (cu->isp_split_type == ISP_VER_SPLIT && tu->width < MIN_ISP_PRED_WIDTH) {
205 28178 *w = MIN_ISP_PRED_WIDTH;
206 28178 has_luma = !(idx % (MIN_ISP_PRED_WIDTH / tu->width));
207 }
208 1032766 return has_luma;
209 }
210
211 436042 static int get_chroma_predict_unit(const CodingUnit *cu, const TransformUnit *tu, const int idx, int *x0, int *y0, int *w, int *h)
212 {
213
2/2
✓ Branch 2 → 3 taken 412724 times.
✓ Branch 2 → 5 taken 23318 times.
436042 if (cu->isp_split_type == ISP_NO_SPLIT) {
214 412724 add_tu_area(tu, x0, y0, w, h);
215 412724 return 1;
216 }
217
2/2
✓ Branch 5 → 6 taken 5917 times.
✓ Branch 5 → 7 taken 17401 times.
23318 if (idx == cu->num_intra_subpartitions - 1) {
218 5917 *x0 = cu->x0;
219 5917 *y0 = cu->y0;
220 5917 *w = cu->cb_width;
221 5917 *h = cu->cb_height;
222 5917 return 1;
223 }
224 17401 return 0;
225 }
226
227 //8.4.5.1 General decoding process for intra blocks
228 1941612 static int predict_intra(VVCLocalContext *lc, const TransformUnit *tu, const int idx, const int target_ch_type)
229 {
230 1941612 const VVCFrameContext *fc = lc->fc;
231 1941612 const CodingUnit *cu = lc->cu;
232 1941612 const VVCTreeType tree_type = cu->tree_type;
233 int x0, y0, w, h, ret;
234
2/2
✓ Branch 2 → 3 taken 472804 times.
✓ Branch 2 → 5 taken 1468808 times.
1941612 if (cu->pred_mode != MODE_INTRA) {
235 472804 ret = add_reconstructed_area(lc, target_ch_type, tu->x0, tu->y0, tu->width, tu->height);
236 472804 return ret;
237 }
238
3/4
✓ Branch 5 → 6 taken 1032766 times.
✓ Branch 5 → 14 taken 436042 times.
✓ Branch 6 → 7 taken 1032766 times.
✗ Branch 6 → 14 not taken.
1468808 if (!target_ch_type && tree_type != DUAL_TREE_CHROMA) {
239
2/2
✓ Branch 8 → 9 taken 1017535 times.
✓ Branch 8 → 14 taken 15231 times.
1032766 if (get_luma_predict_unit(cu, tu, idx, &x0, &y0, &w, &h)) {
240 1017535 ff_vvc_set_neighbour_available(lc, x0, y0, w, h);
241 1017535 fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 0);
242 1017535 ret = add_reconstructed_area(lc, 0, x0, y0, w, h);
243
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1017535 times.
1017535 if (ret < 0)
244 ✗ return ret;
245 }
246 }
247
3/4
✓ Branch 14 → 15 taken 436042 times.
✓ Branch 14 → 27 taken 1032766 times.
✓ Branch 15 → 16 taken 436042 times.
✗ Branch 15 → 27 not taken.
1468808 if (target_ch_type && tree_type != DUAL_TREE_LUMA) {
248
2/2
✓ Branch 17 → 18 taken 418641 times.
✓ Branch 17 → 27 taken 17401 times.
436042 if (get_chroma_predict_unit(cu, tu, idx, &x0, &y0, &w, &h)){
249 418641 ff_vvc_set_neighbour_available(lc, x0, y0, w, h);
250
2/2
✓ Branch 20 → 21 taken 102241 times.
✓ Branch 20 → 22 taken 316400 times.
418641 if (is_cclm(cu->intra_pred_mode_c)) {
251 102241 fc->vvcdsp.intra.intra_cclm_pred(lc, x0, y0, w, h);
252 } else {
253 316400 fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 1);
254 316400 fc->vvcdsp.intra.intra_pred(lc, x0, y0, w, h, 2);
255 }
256 418641 ret = add_reconstructed_area(lc, 1, x0, y0, w, h);
257
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 418641 times.
418641 if (ret < 0)
258 ✗ return ret;
259 }
260 }
261 1468808 return 0;
262 }
263
264 1064855 static void scale_clip(int *coeff, const int nzw, const int w, const int h,
265 const int shift, const int log2_transform_range)
266 {
267 1064855 const int add = 1 << (shift - 1);
268
2/2
✓ Branch 7 → 3 taken 10950268 times.
✓ Branch 7 → 8 taken 1064855 times.
12015123 for (int y = 0; y < h; y++) {
269 10950268 int *p = coeff + y * w;
270
2/2
✓ Branch 5 → 4 taken 53950238 times.
✓ Branch 5 → 6 taken 10950268 times.
64900506 for (int x = 0; x < nzw; x++) {
271 53950238 *p = av_clip_intp2((*p + add) >> shift, log2_transform_range);
272 53950238 p++;
273 }
274 10950268 memset(p, 0, sizeof(*p) * (w - nzw));
275 }
276 1064855 }
277
278 1078302 static void scale(int *out, const int *in, const int w, const int h, const int shift)
279 {
280 1078302 const int add = 1 << (shift - 1);
281
2/2
✓ Branch 7 → 3 taken 11007456 times.
✓ Branch 7 → 8 taken 1078302 times.
12085758 for (int y = 0; y < h; y++) {
282
2/2
✓ Branch 5 → 4 taken 176193492 times.
✓ Branch 5 → 6 taken 11007456 times.
187200948 for (int x = 0; x < w; x++) {
283 176193492 int *o = out + y * w + x;
284 176193492 const int *i = in + y * w + x;
285 176193492 *o = (*i + add) >> shift;
286 }
287 }
288 1078302 }
289
290 // part of 8.7.3 Scaling process for transform coefficients
291 1467871 static void derive_qp(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
292 {
293 1467871 const VVCSPS *sps = lc->fc->ps.sps;
294 1467871 const H266RawSliceHeader *rsh = lc->sc->sh.r;
295 1467871 const CodingUnit *cu = lc->cu;
296
8/8
✓ Branch 2 → 3 taken 495965 times.
✓ Branch 2 → 7 taken 971906 times.
✓ Branch 3 → 4 taken 54924 times.
✓ Branch 3 → 7 taken 441041 times.
✓ Branch 4 → 5 taken 46744 times.
✓ Branch 4 → 7 taken 8180 times.
✓ Branch 5 → 6 taken 31655 times.
✓ Branch 5 → 7 taken 15089 times.
1467871 const bool is_jcbcr = tb->c_idx && tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
297
2/2
✓ Branch 8 → 9 taken 31655 times.
✓ Branch 8 → 10 taken 1436216 times.
1467871 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
298
2/2
✓ Branch 11 → 12 taken 971906 times.
✓ Branch 11 → 13 taken 495965 times.
1467871 const int qp = cu->qp[idx] + (idx ? 0 : sps->qp_bd_offset);
299 1467871 const int act_offset[] = { -5, 1, 3, 1 };
300
2/2
✓ Branch 14 → 15 taken 21078 times.
✓ Branch 14 → 16 taken 1446793 times.
1467871 const int qp_act_offset = cu->act_enabled_flag ? act_offset[idx] : 0;
301
302
2/2
✓ Branch 17 → 18 taken 56567 times.
✓ Branch 17 → 19 taken 1411304 times.
1467871 if (tb->ts) {
303 56567 const int qp_prime_ts_min = 4 + 6 * sps->r->sps_min_qp_prime_ts;
304
305 56567 tb->qp = av_clip(qp + qp_act_offset, qp_prime_ts_min, 63 + sps->qp_bd_offset);
306 56567 tb->rect_non_ts_flag = 0;
307 56567 tb->bd_shift = 10;
308 } else {
309 1411304 const int log_sum = tb->log2_tb_width + tb->log2_tb_height;
310 1411304 const int rect_non_ts_flag = log_sum & 1;
311
312 1411304 tb->qp = av_clip(qp + qp_act_offset, 0, 63 + sps->qp_bd_offset);
313 1411304 tb->rect_non_ts_flag = rect_non_ts_flag;
314 1411304 tb->bd_shift = sps->bit_depth + rect_non_ts_flag + (log_sum / 2)
315 1411304 + 10 - sps->log2_transform_range + rsh->sh_dep_quant_used_flag;
316 }
317 1467871 tb->bd_offset = (1 << tb->bd_shift) >> 1;
318 1467871 }
319
320 static const uint8_t rem6[63 + 8 * 6 + 1] = {
321 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
322 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
323 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
324 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
325 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
326 };
327
328 static const uint8_t div6[63 + 8 * 6 + 1] = {
329 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
330 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
331 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
332 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
333 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
334 };
335
336 const static int level_scale[2][6] = {
337 { 40, 45, 51, 57, 64, 72 },
338 { 57, 64, 72, 80, 90, 102 }
339 };
340
341 //8.7.3 Scaling process for transform coefficients
342 1215183 static av_always_inline int derive_scale(const TransformBlock *tb, const int sh_dep_quant_used_flag)
343 {
344
4/4
✓ Branch 2 → 3 taken 953955 times.
✓ Branch 2 → 5 taken 261228 times.
✓ Branch 3 → 4 taken 897388 times.
✓ Branch 3 → 5 taken 56567 times.
1215183 const int addin = sh_dep_quant_used_flag && !tb->ts;
345 1215183 const int qp = tb->qp + addin;
346
347 1215183 return level_scale[tb->rect_non_ts_flag][rem6[qp]] << div6[qp];
348 }
349
350 //8.7.3 Scaling process for transform coefficients
351 1215183 static const uint8_t* derive_scale_m(const VVCLocalContext *lc, const TransformBlock *tb, uint8_t *scale_m)
352 {
353 //Table 38 – Specification of the scaling matrix identifier variable id according to predMode, cIdx, nTbW, and nTbH
354 1215183 const int ids[2][3][6] = {
355 {
356 { 0, 2, 8, 14, 20, 26 },
357 { 0, 3, 9, 15, 21, 21 },
358 { 0, 4, 10, 16, 22, 22 }
359 },
360 {
361 { 0, 5, 11, 17, 23, 27 },
362 { 0, 6, 12, 18, 24, 24 },
363 { 1, 7, 13, 19, 25, 25 },
364 }
365 };
366 1215183 const VVCFrameParamSets *ps = &lc->fc->ps;
367 1215183 const VVCSPS *sps = ps->sps;
368 1215183 const H266RawSliceHeader *rsh = lc->sc->sh.r;
369 1215183 const CodingUnit *cu = lc->cu;
370 1215183 const VVCScalingList *sl = ps->sl;
371 1215183 const int id = ids[cu->pred_mode != MODE_INTRA][tb->c_idx][FFMAX(tb->log2_tb_height, tb->log2_tb_width) - 1];
372
4/4
✓ Branch 2 → 3 taken 1212332 times.
✓ Branch 2 → 6 taken 2851 times.
✓ Branch 3 → 4 taken 205468 times.
✓ Branch 3 → 5 taken 1006864 times.
1215183 const int log2_matrix_size = (id < 2) ? 1 : (id < 8) ? 2 : 3;
373 1215183 uint8_t *p = scale_m;
374
375
4/4
✓ Branch 7 → 8 taken 99612 times.
✓ Branch 7 → 13 taken 1115571 times.
✓ Branch 8 → 9 taken 97122 times.
✓ Branch 8 → 13 taken 2490 times.
1215183 if (!rsh->sh_explicit_scaling_list_used_flag || tb->ts ||
376
3/4
✓ Branch 9 → 10 taken 97122 times.
✗ Branch 9 → 11 not taken.
✓ Branch 10 → 11 taken 65726 times.
✓ Branch 10 → 13 taken 31396 times.
97122 (sps->r->sps_scaling_matrix_for_lfnst_disabled_flag && cu->apply_lfnst_flag[tb->c_idx]) ||
377
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 14 taken 65726 times.
65726 (sps->r->sps_scaling_matrix_for_alternative_colour_space_disabled_flag &&
378
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ sps->r->sps_scaling_matrix_designated_colour_space_flag == cu->act_enabled_flag))
379 1149457 return ff_vvc_default_scale_m;
380
381
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 65726 times.
65726 if (!sl) {
382 ✗ av_log(lc->fc->log_ctx, AV_LOG_WARNING, "bug: no scaling list aps, id = %d", ps->ph.r->ph_scaling_list_aps_id);
383 ✗ return ff_vvc_default_scale_m;
384 }
385
386
2/2
✓ Branch 22 → 18 taken 326806 times.
✓ Branch 22 → 23 taken 65726 times.
392532 for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
387 326806 const int off = y << log2_matrix_size >> tb->log2_tb_height << log2_matrix_size;
388 326806 const uint8_t *m = &sl->scaling_matrix_rec[id][off];
389
390
2/2
✓ Branch 20 → 19 taken 1859082 times.
✓ Branch 20 → 21 taken 326806 times.
2185888 for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++)
391 1859082 *p++ = m[x << log2_matrix_size >> tb->log2_tb_width];
392 }
393
4/6
✓ Branch 23 → 24 taken 27312 times.
✓ Branch 23 → 27 taken 38414 times.
✓ Branch 24 → 25 taken 27312 times.
✗ Branch 24 → 27 not taken.
✓ Branch 25 → 26 taken 27312 times.
✗ Branch 25 → 27 not taken.
65726 if (id >= SL_START_16x16 && !tb->min_scan_x && !tb->min_scan_y)
394 27312 *scale_m = sl->scaling_matrix_dc_rec[id - SL_START_16x16];
395
396 65726 return scale_m;
397 }
398
399 //8.7.3 Scaling process for transform coefficients
400 12612036 static av_always_inline int scale_coeff(const TransformBlock *tb, int coeff,
401 const int scale, const int scale_m, const int log2_transform_range)
402 {
403 12612036 coeff = ((int64_t) coeff * scale * scale_m + tb->bd_offset) >> tb->bd_shift;
404 12612036 coeff = av_clip_intp2(coeff, log2_transform_range);
405 12612036 return coeff;
406 }
407
408 1215183 static void dequant(const VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
409 {
410 uint8_t tmp[MAX_TB_SIZE * MAX_TB_SIZE];
411 1215183 const H266RawSliceHeader *rsh = lc->sc->sh.r;
412 1215183 const VVCSPS *sps = lc->fc->ps.sps;
413 1215183 const uint8_t *scale_m = derive_scale_m(lc, tb, tmp);
414 int scale;
415
416 1215183 derive_qp(lc, tu, tb);
417 1215183 scale = derive_scale(tb, rsh->sh_dep_quant_used_flag);
418
419
2/2
✓ Branch 13 → 6 taken 4346033 times.
✓ Branch 13 → 14 taken 1215183 times.
5561216 for (int y = tb->min_scan_y; y <= tb->max_scan_y; y++) {
420
2/2
✓ Branch 11 → 7 taken 24869667 times.
✓ Branch 11 → 12 taken 4346033 times.
29215700 for (int x = tb->min_scan_x; x <= tb->max_scan_x; x++) {
421 24869667 int *coeff = tb->coeffs + y * tb->tb_width + x;
422
423
2/2
✓ Branch 7 → 8 taken 12612036 times.
✓ Branch 7 → 10 taken 12257631 times.
24869667 if (*coeff)
424 12612036 *coeff = scale_coeff(tb, *coeff, scale, *scale_m, sps->log2_transform_range);
425 24869667 scale_m++;
426 }
427 }
428 1215183 }
429
430 //transmatrix[0][0]
431 #define DCT_A 64
432 1142022 static void itx_2d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
433 {
434 1142022 const VVCSPS *sps = fc->ps.sps;
435 1142022 const int w = tb->tb_width;
436 1142022 const int h = tb->tb_height;
437 1142022 const size_t nzw = tb->max_scan_x + 1;
438 1142022 const size_t nzh = tb->max_scan_y + 1;
439 1142022 const int shift[] = { 7, 5 + sps->log2_transform_range - sps->bit_depth };
440
441
9/10
✓ Branch 2 → 3 taken 425657 times.
✓ Branch 2 → 11 taken 716365 times.
✓ Branch 3 → 4 taken 117378 times.
✓ Branch 3 → 11 taken 308279 times.
✓ Branch 4 → 5 taken 83782 times.
✓ Branch 4 → 11 taken 33596 times.
✓ Branch 5 → 6 taken 77167 times.
✓ Branch 5 → 11 taken 6615 times.
✓ Branch 6 → 7 taken 77167 times.
✗ Branch 6 → 11 not taken.
1142022 if (w == h && nzw == 1 && nzh == 1 && trh == VVC_DCT2 && trv == VVC_DCT2) {
442 77167 const int add[] = { 1 << (shift[0] - 1), 1 << (shift[1] - 1) };
443 77167 const int t = (tb->coeffs[0] * DCT_A + add[0]) >> shift[0];
444 77167 const int dc = (t * DCT_A + add[1]) >> shift[1];
445
446
2/2
✓ Branch 9 → 8 taken 20574736 times.
✓ Branch 9 → 10 taken 77167 times.
20651903 for (int i = 0; i < w * h; i++)
447 20574736 tb->coeffs[i] = dc;
448
449 77167 return;
450 }
451
452
2/2
✓ Branch 14 → 12 taken 4672666 times.
✓ Branch 14 → 15 taken 1064855 times.
5737521 for (int x = 0; x < nzw; x++)
453 4672666 fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs + x, w, nzh);
454 1064855 scale_clip(tb->coeffs, nzw, w, h, shift[0], sps->log2_transform_range);
455
456
2/2
✓ Branch 19 → 17 taken 10950268 times.
✓ Branch 19 → 20 taken 1064855 times.
12015123 for (int y = 0; y < h; y++)
457 10950268 fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs + y * w, 1, nzw);
458 1064855 scale(tb->coeffs, tb->coeffs, w, h, shift[1]);
459 }
460
461 16594 static void itx_1d(const VVCFrameContext *fc, TransformBlock *tb, const enum VVCTxType trh, const enum VVCTxType trv)
462 {
463 16594 const VVCSPS *sps = fc->ps.sps;
464 16594 const int w = tb->tb_width;
465 16594 const int h = tb->tb_height;
466 16594 const size_t nzw = tb->max_scan_x + 1;
467 16594 const size_t nzh = tb->max_scan_y + 1;
468
469
12/12
✓ Branch 2 → 3 taken 13674 times.
✓ Branch 2 → 5 taken 2920 times.
✓ Branch 3 → 4 taken 5047 times.
✓ Branch 3 → 5 taken 8627 times.
✓ Branch 4 → 5 taken 2097 times.
✓ Branch 4 → 8 taken 2950 times.
✓ Branch 5 → 6 taken 2920 times.
✓ Branch 5 → 12 taken 10724 times.
✓ Branch 6 → 7 taken 822 times.
✓ Branch 6 → 12 taken 2098 times.
✓ Branch 7 → 8 taken 197 times.
✓ Branch 7 → 12 taken 625 times.
16594 if ((w > 1 && nzw == 1 && trh == VVC_DCT2) || (h > 1 && nzh == 1 && trv == VVC_DCT2)) {
470 3147 const int shift = 6 + sps->log2_transform_range - sps->bit_depth;
471 3147 const int add = 1 << (shift - 1);
472 3147 const int dc = (tb->coeffs[0] * DCT_A + add) >> shift;
473
474
2/2
✓ Branch 10 → 9 taken 101056 times.
✓ Branch 10 → 11 taken 3147 times.
104203 for (int i = 0; i < w * h; i++)
475 101056 tb->coeffs[i] = dc;
476
477 3147 return;
478 }
479
480
2/2
✓ Branch 12 → 13 taken 10724 times.
✓ Branch 12 → 14 taken 2723 times.
13447 if (w > 1)
481 10724 fc->vvcdsp.itx.itx[trh][tb->log2_tb_width - 1](tb->coeffs, 1, nzw);
482 else
483 2723 fc->vvcdsp.itx.itx[trv][tb->log2_tb_height - 1](tb->coeffs, 1, nzh);
484 13447 scale(tb->coeffs, tb->coeffs, w, h, 6 + sps->log2_transform_range - sps->bit_depth);
485 }
486
487 3683 static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const CodingUnit *cu)
488 {
489 3683 const VVCSPS *sps = lc->fc->ps.sps;
490
2/2
✓ Branch 2 → 3 taken 174 times.
✓ Branch 2 → 4 taken 3509 times.
3683 const IntraPredMode mode = tb->c_idx ? cu->intra_pred_mode_c : cu->intra_pred_mode_y;
491 3683 const int vertical = mode == INTRA_VERT;
492 3683 lc->fc->vvcdsp.itx.transform_bdpcm(tb->coeffs, tb->tb_width, tb->tb_height,
493 3683 vertical, sps->log2_transform_range);
494
2/2
✓ Branch 6 → 7 taken 2422 times.
✓ Branch 6 → 8 taken 1261 times.
3683 if (vertical)
495 2422 tb->max_scan_y = tb->tb_height - 1;
496 else
497 1261 tb->max_scan_x = tb->tb_width - 1;
498 3683 }
499
500 1215183 static void lmcs_scale_chroma(VVCLocalContext *lc, TransformUnit *tu, TransformBlock *tb, const int target_ch_type)
501 {
502 1215183 const VVCFrameContext *fc = lc->fc;
503 1215183 const VVCSH *sh = &lc->sc->sh;
504 1215183 const CodingUnit *cu = lc->cu;
505 1215183 const int c_idx = tb->c_idx;
506 1215183 const int ch_type = c_idx > 0;
507 1215183 const int w = tb->tb_width;
508 1215183 const int h = tb->tb_height;
509
7/8
✓ Branch 2 → 3 taken 329741 times.
✓ Branch 2 → 7 taken 885442 times.
✓ Branch 3 → 4 taken 132690 times.
✓ Branch 3 → 7 taken 197051 times.
✓ Branch 4 → 5 taken 132690 times.
✗ Branch 4 → 7 not taken.
✓ Branch 5 → 6 taken 130617 times.
✓ Branch 5 → 7 taken 2073 times.
1215183 const int chroma_scale = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4);
510
4/4
✓ Branch 8 → 9 taken 68895 times.
✓ Branch 8 → 11 taken 1146288 times.
✓ Branch 9 → 10 taken 54924 times.
✓ Branch 9 → 11 taken 13971 times.
1215183 const int has_jcbcr = tu->joint_cbcr_residual_flag && c_idx;
511
512
2/2
✓ Branch 22 → 13 taken 1270107 times.
✓ Branch 22 → 23 taken 1215183 times.
2485290 for (int j = 0; j < 1 + has_jcbcr; j++) {
513 1270107 const bool is_jcbcr = j > 0;
514 1270107 const int jcbcr_idx = CB + tu->coded_flag[CB];
515 1270107 TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx];
516
2/2
✓ Branch 13 → 14 taken 54924 times.
✓ Branch 13 → 15 taken 1215183 times.
1270107 int *coeffs = is_jcbcr ? jcbcr->coeffs : tb->coeffs;
517
518
4/4
✓ Branch 16 → 17 taken 1215183 times.
✓ Branch 16 → 19 taken 54924 times.
✓ Branch 17 → 18 taken 54924 times.
✓ Branch 17 → 19 taken 1160259 times.
1270107 if (!j && has_jcbcr) {
519 54924 const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
520 54924 const int shift = tu->coded_flag[CB] ^ tu->coded_flag[CR];
521 54924 fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, w, h, c_sign, shift);
522 }
523
2/2
✓ Branch 19 → 20 taken 157766 times.
✓ Branch 19 → 21 taken 1112341 times.
1270107 if (chroma_scale)
524 157766 fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0);
525 }
526 1215183 }
527
528 1941612 static void add_residual(const VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type)
529 {
530 1941612 const VVCFrameContext *fc = lc->fc;
531 1941612 const CodingUnit *cu = lc->cu;
532
533
2/2
✓ Branch 13 → 3 taken 3805699 times.
✓ Branch 13 → 14 taken 1941612 times.
5747311 for (int i = 0; i < tu->nb_tbs; i++) {
534 3805699 TransformBlock *tb = tu->tbs + i;
535 3805699 const int c_idx = tb->c_idx;
536 3805699 const int ch_type = c_idx > 0;
537 3805699 const ptrdiff_t stride = fc->frame->linesize[c_idx];
538
6/6
✓ Branch 3 → 4 taken 2193431 times.
✓ Branch 3 → 7 taken 1612268 times.
✓ Branch 4 → 5 taken 2144663 times.
✓ Branch 4 → 7 taken 48768 times.
✓ Branch 5 → 6 taken 1595945 times.
✓ Branch 5 → 8 taken 548718 times.
5401644 const bool has_residual = tb->has_coeffs || cu->act_enabled_flag ||
539
2/2
✓ Branch 6 → 7 taken 77507 times.
✓ Branch 6 → 8 taken 1518438 times.
1595945 (c_idx && tu->joint_cbcr_residual_flag);
540 3805699 uint8_t *dst = POS(c_idx, tb->x0, tb->y0);
541
542
4/4
✓ Branch 9 → 10 taken 2570715 times.
✓ Branch 9 → 12 taken 1234984 times.
✓ Branch 10 → 11 taken 1294034 times.
✓ Branch 10 → 12 taken 1276681 times.
3805699 if (ch_type == target_ch_type && has_residual)
543 1294034 fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
544 }
545 1941612 }
546
547 1941612 static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type)
548 {
549 1941612 const VVCFrameContext *fc = lc->fc;
550 1941612 const CodingUnit *cu = lc->cu;
551 1941612 TransformBlock *tbs = tu->tbs;
552
4/4
✓ Branch 2 → 3 taken 30308 times.
✓ Branch 2 → 5 taken 1911304 times.
✓ Branch 3 → 4 taken 15154 times.
✓ Branch 3 → 5 taken 15154 times.
1941612 const bool is_act_luma = cu->act_enabled_flag && target_ch_type == LUMA;
553
554
2/2
✓ Branch 28 → 7 taken 3805699 times.
✓ Branch 28 → 29 taken 1941612 times.
5747311 for (int i = 0; i < tu->nb_tbs; i++) {
555 3805699 TransformBlock *tb = tbs + i;
556 3805699 const int c_idx = tb->c_idx;
557 3805699 const int ch_type = c_idx > 0;
558
6/6
✓ Branch 7 → 8 taken 3760237 times.
✓ Branch 7 → 10 taken 45462 times.
✓ Branch 8 → 9 taken 3714775 times.
✓ Branch 8 → 11 taken 45462 times.
✓ Branch 9 → 10 taken 2525253 times.
✓ Branch 9 → 11 taken 1189522 times.
3805699 const bool do_itx = is_act_luma || !cu->act_enabled_flag && ch_type == target_ch_type;
559
560
4/4
✓ Branch 12 → 13 taken 1612268 times.
✓ Branch 12 → 27 taken 2193431 times.
✓ Branch 13 → 14 taken 1215183 times.
✓ Branch 13 → 27 taken 397085 times.
3805699 if (tb->has_coeffs && do_itx) {
561
2/2
✓ Branch 14 → 15 taken 3683 times.
✓ Branch 14 → 16 taken 1211500 times.
1215183 if (cu->bdpcm_flag[tb->c_idx])
562 3683 transform_bdpcm(tb, lc, cu);
563 1215183 dequant(lc, tu, tb);
564
2/2
✓ Branch 17 → 18 taken 1158616 times.
✓ Branch 17 → 26 taken 56567 times.
1215183 if (!tb->ts) {
565 enum VVCTxType trh, trv;
566
567
2/2
✓ Branch 18 → 19 taken 175544 times.
✓ Branch 18 → 20 taken 983072 times.
1158616 if (cu->apply_lfnst_flag[c_idx])
568 175544 ilfnst_transform(lc, tb);
569 1158616 derive_transform_type(fc, lc, tb, &trh, &trv);
570
4/4
✓ Branch 21 → 22 taken 1155696 times.
✓ Branch 21 → 24 taken 2920 times.
✓ Branch 22 → 23 taken 1142022 times.
✓ Branch 22 → 24 taken 13674 times.
1158616 if (tb->tb_width > 1 && tb->tb_height > 1)
571 1142022 itx_2d(fc, tb, trh, trv);
572 else
573 16594 itx_1d(fc, tb, trh, trv);
574 }
575 1215183 lmcs_scale_chroma(lc, tu, tb, target_ch_type);
576 }
577 }
578
579
2/2
✓ Branch 29 → 30 taken 15154 times.
✓ Branch 29 → 31 taken 1926458 times.
1941612 if (is_act_luma) {
580 15154 fc->vvcdsp.itx.adaptive_color_transform(
581 15154 tbs[LUMA].coeffs, tbs[CB].coeffs, tbs[CR].coeffs,
582 tbs[LUMA].tb_width, tbs[LUMA].tb_height);
583 }
584
585 1941612 add_residual(lc, tu, target_ch_type);
586 1941612 }
587
588 1312730 static int reconstruct(VVCLocalContext *lc)
589 {
590 1312730 VVCFrameContext *fc = lc->fc;
591 1312730 CodingUnit *cu = lc->cu;
592 1312730 const int start = cu->tree_type == DUAL_TREE_CHROMA;
593
4/4
✓ Branch 2 → 3 taken 1293602 times.
✓ Branch 2 → 5 taken 19128 times.
✓ Branch 3 → 4 taken 590107 times.
✓ Branch 3 → 5 taken 703495 times.
1312730 const int end = fc->ps.sps->r->sps_chroma_format_idc && (cu->tree_type != DUAL_TREE_LUMA);
594 int ret;
595
596
2/2
✓ Branch 15 → 7 taken 1663050 times.
✓ Branch 15 → 16 taken 1312730 times.
2975780 for (int ch_type = start; ch_type <= end; ch_type++) {
597 1663050 TransformUnit *tu = cu->tus.head;
598
2/2
✓ Branch 13 → 8 taken 1941612 times.
✓ Branch 13 → 14 taken 1663050 times.
3604662 for (int i = 0; tu; i++) {
599 1941612 ret = predict_intra(lc, tu, i, ch_type);
600
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 1941612 times.
1941612 if (ret < 0)
601 ✗ return ret;
602 1941612 itransform(lc, tu, ch_type);
603 1941612 tu = tu->next;
604 }
605 }
606 1312730 return 0;
607 }
608
609 #define IBC_POS(c_idx, x, y) \
610 (fc->tab.ibc_vir_buf[c_idx] + \
611 (x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * ibc_stride)
612 #define IBC_X(x) ((x) & ((fc->tab.sz.ibc_buffer_width >> hs) - 1))
613 #define IBC_Y(y) ((y) & ((1 << sps->ctb_log2_size_y >> vs) - 1))
614
615 167524 static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
616 {
617 167524 const CodingUnit *cu = lc->cu;
618 167524 const PredictionUnit *pu = &cu->pu;
619 167524 const VVCFrameContext *fc = lc->fc;
620 167524 const VVCSPS *sps = fc->ps.sps;
621 167524 const Mv *bv = &pu->mi.mv[L0][0];
622 167524 const int hs = sps->hshift[c_idx];
623 167524 const int vs = sps->vshift[c_idx];
624 167524 const int ps = sps->pixel_shift;
625 167524 const int ref_x = IBC_X((cu->x0 >> hs) + (bv->x >> (4 + hs)));
626 167524 const int ref_y = IBC_Y((cu->y0 >> vs) + (bv->y >> (4 + vs)));
627 167524 const int w = cu->cb_width >> hs;
628 167524 const int h = cu->cb_height >> vs;
629 167524 const int ibc_buf_width = fc->tab.sz.ibc_buffer_width >> hs; ///< IbcBufWidthY and IbcBufWidthC
630 167524 const int rw = FFMIN(w, ibc_buf_width - ref_x);
631 167524 const int ibc_stride = ibc_buf_width << ps;
632 167524 const int dst_stride = fc->frame->linesize[c_idx];
633 167524 const uint8_t *ibc_buf = IBC_POS(c_idx, ref_x, ref_y);
634 167524 uint8_t *dst = POS(c_idx, cu->x0, cu->y0);
635
636 167524 av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, rw << ps, h);
637
638
2/2
✓ Branch 3 → 4 taken 2354 times.
✓ Branch 3 → 5 taken 165170 times.
167524 if (w > rw) {
639 //wrap around, left part
640 2354 ibc_buf = IBC_POS(c_idx, 0, ref_y);
641 2354 dst += rw << ps;
642 2354 av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, (w - rw) << ps, h);
643 }
644 167524 }
645
646 87174 static void vvc_predict_ibc(const VVCLocalContext *lc)
647 {
648 87174 const H266RawSPS *rsps = lc->fc->ps.sps->r;
649
650 87174 intra_block_copy(lc, LUMA);
651
3/4
✓ Branch 3 → 4 taken 40175 times.
✓ Branch 3 → 7 taken 46999 times.
✓ Branch 4 → 5 taken 40175 times.
✗ Branch 4 → 7 not taken.
87174 if (lc->cu->tree_type == SINGLE_TREE && rsps->sps_chroma_format_idc) {
652 40175 intra_block_copy(lc, CB);
653 40175 intra_block_copy(lc, CR);
654 }
655 87174 }
656
657 258152 static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
658 {
659 258152 const VVCFrameContext *fc = lc->fc;
660 258152 const VVCSPS *sps = fc->ps.sps;
661 int start, end;
662
663 258152 ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
664
665
2/2
✓ Branch 6 → 4 taken 531705 times.
✓ Branch 6 → 7 taken 258152 times.
789857 for (int c_idx = start; c_idx < end; c_idx++) {
666 531705 const int hs = sps->hshift[c_idx];
667 531705 const int vs = sps->vshift[c_idx];
668 531705 const int ps = sps->pixel_shift;
669 531705 const int x = IBC_X(cu->x0 >> hs);
670 531705 const int y = IBC_Y(cu->y0 >> vs);
671 531705 const int src_stride = fc->frame->linesize[c_idx];
672 531705 const int ibc_stride = fc->tab.sz.ibc_buffer_width >> hs << ps;
673 531705 const uint8_t *src = POS(c_idx, cu->x0, cu->y0);
674 531705 uint8_t *ibc_buf = IBC_POS(c_idx, x, y);
675
676 531705 av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride, cu->cb_width >> hs << ps , cu->cb_height >> vs);
677 }
678 258152 }
679
680 252688 int ff_vvc_palette_derive_scale(VVCLocalContext *lc, const TransformUnit *tu, TransformBlock *tb)
681 {
682 252688 const VVCSPS *sps = lc->fc->ps.sps;
683 252688 const int qp_prime_ts_min = 4 + 6 * sps->r->sps_min_qp_prime_ts;
684 int qp;
685
686 252688 derive_qp(lc, tu, tb);
687 252688 qp = FFMAX(qp_prime_ts_min, tb->qp);
688 252688 return level_scale[0][rem6[qp]] << div6[qp];
689 }
690
691 // 8.4.5.3 Decoding process for palette mode
692 6977 static void vvc_predict_palette(VVCLocalContext *lc)
693 {
694 6977 const VVCFrameContext *fc = lc->fc;
695 6977 const CodingUnit *cu = lc->cu;
696 6977 TransformUnit *tu = cu->tus.head;
697 6977 const VVCSPS *sps = fc->ps.sps;
698 6977 const int ps = sps->pixel_shift;
699
700
2/2
✓ Branch 5 → 3 taken 19123 times.
✓ Branch 5 → 6 taken 6977 times.
26100 for (int i = 0; i < tu->nb_tbs; i++) {
701 19123 TransformBlock *tb = &tu->tbs[i];
702 19123 const int c_idx = tb->c_idx;
703 19123 const int w = tb->tb_width;
704 19123 const int h = tb->tb_height;
705 19123 const ptrdiff_t stride = fc->frame->linesize[c_idx];
706 19123 uint8_t *dst = POS(c_idx, cu->x0, cu->y0);
707
708 19123 av_image_copy_plane(dst, stride, (uint8_t*)tb->coeffs, w << ps, w << ps, h);
709 }
710 6977 }
711
712 66887 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const int ry)
713 {
714 66887 const VVCFrameContext *fc = lc->fc;
715 66887 const VVCSPS *sps = fc->ps.sps;
716 66887 const int x_ctb = rx << sps->ctb_log2_size_y;
717 66887 const int y_ctb = ry << sps->ctb_log2_size_y;
718 66887 CodingUnit *cu = fc->tab.cus[rs];
719 66887 int ret = 0;
720
721 66887 lc->num_ras[0] = lc->num_ras[1] = 0;
722 66887 lc->lmcs.x_vpdu = -1;
723 66887 lc->lmcs.y_vpdu = -1;
724 66887 ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
725
2/2
✓ Branch 24 → 4 taken 1752802 times.
✓ Branch 24 → 25 taken 66887 times.
1819689 while (cu) {
726 1752802 lc->cu = cu;
727
728
2/2
✓ Branch 4 → 5 taken 16327 times.
✓ Branch 4 → 6 taken 1736475 times.
1752802 if (cu->ciip_flag)
729 16327 ff_vvc_predict_ciip(lc);
730
2/2
✓ Branch 6 → 7 taken 87174 times.
✓ Branch 6 → 8 taken 1649301 times.
1736475 else if (cu->pred_mode == MODE_IBC)
731 87174 vvc_predict_ibc(lc);
732
2/2
✓ Branch 8 → 9 taken 6977 times.
✓ Branch 8 → 10 taken 1642324 times.
1649301 else if (cu->pred_mode == MODE_PLT)
733 6977 vvc_predict_palette(lc);
734
2/2
✓ Branch 10 → 11 taken 1312730 times.
✓ Branch 10 → 12 taken 440072 times.
1752802 if (cu->coded_flag) {
735 1312730 ret = reconstruct(lc);
736 } else {
737
1/2
✓ Branch 12 → 13 taken 440072 times.
✗ Branch 12 → 16 not taken.
440072 if (cu->tree_type != DUAL_TREE_CHROMA) {
738 440072 ret = add_reconstructed_area(lc, LUMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
739
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 440072 times.
440072 if (ret < 0)
740 ✗ return ret;
741 }
742
4/4
✓ Branch 16 → 17 taken 423561 times.
✓ Branch 16 → 21 taken 16511 times.
✓ Branch 17 → 18 taken 387372 times.
✓ Branch 17 → 21 taken 36189 times.
440072 if (sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA) {
743 387372 ret = add_reconstructed_area(lc, CHROMA, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
744
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 387372 times.
387372 if (ret < 0)
745 ✗ return ret;
746 }
747 }
748
2/2
✓ Branch 21 → 22 taken 258152 times.
✓ Branch 21 → 23 taken 1494650 times.
1752802 if (sps->r->sps_ibc_enabled_flag)
749 258152 ibc_fill_vir_buf(lc, cu);
750 1752802 cu = cu->next;
751 }
752 66887 ff_vvc_ctu_free_cus(fc->tab.cus + rs);
753 66887 return ret;
754 }
755