FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/intra_template.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 624 630 99.0%
Functions: 53 90 58.9%
Branches: 394 404 97.5%

Line Branch Exec Source
1 /*
2 * VVC intra prediction DSP
3 *
4 * Copyright (C) 2021-2023 Nuomi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavcodec/bit_depth_template.c"
24
25 #include "intra.h"
26
27 #define POS(x, y) src[(x) + stride * (y)]
28
29 123790 static av_always_inline void FUNC(cclm_linear_pred)(VVCFrameContext *fc, const int x0, const int y0,
30 const int w, const int h, const pixel* pdsy, const int *a, const int *b, const int *k)
31 {
32 123790 const VVCSPS *sps = fc->ps.sps;
33
2/2
✓ Branch 0 taken 123790 times.
✓ Branch 1 taken 61895 times.
371370 for (int i = 0; i < VVC_MAX_SAMPLE_ARRAYS - 1; i++) {
34 247580 const int c_idx = i + 1;
35 247580 const int x = x0 >> sps->hshift[c_idx];
36 247580 const int y = y0 >> sps->vshift[c_idx];
37 247580 const ptrdiff_t stride = fc->frame->linesize[c_idx] / sizeof(pixel);
38 247580 pixel *src = (pixel*)fc->frame->data[c_idx] + x + y * stride;
39
2/2
✓ Branch 0 taken 1259564 times.
✓ Branch 1 taken 123790 times.
2766708 for (int y = 0; y < h; y++) {
40
2/2
✓ Branch 0 taken 20282784 times.
✓ Branch 1 taken 1259564 times.
43084696 for (int x = 0; x < w; x++) {
41 40565568 const int dsy = pdsy[y * w + x];
42 40565568 const int pred = ((dsy * a[i]) >> k[i]) + b[i];
43 40565568 POS(x, y) = CLIP(pred);
44 }
45 }
46 }
47 123790 }
48
49 #define MAX_PICK_POS 4
50 #define TOP 0
51 #define LEFT 1
52
53 642 static av_always_inline void FUNC(cclm_get_params_default)(int *a, int *b, int *k)
54 {
55
2/2
✓ Branch 0 taken 642 times.
✓ Branch 1 taken 321 times.
1926 for (int i = 0; i < 2; i++) {
56 1284 a[i] = k[i] = 0;
57 1284 b[i] = 1 << (BIT_DEPTH - 1);
58 }
59 642 }
60
61 123790 static av_always_inline int FUNC(cclm_get_select_pos)(const VVCLocalContext *lc,
62 const int x, const int y, const int w, const int h, const int avail_t, const int avail_l,
63 int cnt[2], int pos[2][MAX_PICK_POS])
64 {
65 123790 const enum IntraPredMode mode = lc->cu->intra_pred_mode_c;
66
6/6
✓ Branch 0 taken 59659 times.
✓ Branch 1 taken 2236 times.
✓ Branch 2 taken 58176 times.
✓ Branch 3 taken 1483 times.
✓ Branch 4 taken 24098 times.
✓ Branch 5 taken 34078 times.
123790 const int num_is4 = !avail_t || !avail_l || mode != INTRA_LT_CCLM;
67 int num_samp[2];
68
69
2/2
✓ Branch 0 taken 36952 times.
✓ Branch 1 taken 24943 times.
123790 if (mode == INTRA_LT_CCLM) {
70
2/2
✓ Branch 0 taken 35156 times.
✓ Branch 1 taken 1796 times.
73904 num_samp[TOP] = avail_t ? w : 0;
71
2/2
✓ Branch 0 taken 35874 times.
✓ Branch 1 taken 1078 times.
73904 num_samp[LEFT] = avail_l ? h : 0;
72 } else {
73
4/4
✓ Branch 0 taken 24503 times.
✓ Branch 1 taken 440 times.
✓ Branch 2 taken 13066 times.
✓ Branch 3 taken 11437 times.
49886 num_samp[TOP] = (avail_t && mode == INTRA_T_CCLM) ? ff_vvc_get_top_available(lc, x, y, w + FFMIN(w, h), 1) : 0;
74
4/4
✓ Branch 0 taken 24538 times.
✓ Branch 1 taken 405 times.
✓ Branch 2 taken 11556 times.
✓ Branch 3 taken 12982 times.
49886 num_samp[LEFT] = (avail_l && mode == INTRA_L_CCLM) ? ff_vvc_get_left_available(lc, x, y, h + FFMIN(w, h), 1) : 0;
75 }
76
4/4
✓ Branch 0 taken 13673 times.
✓ Branch 1 taken 48222 times.
✓ Branch 2 taken 321 times.
✓ Branch 3 taken 13352 times.
123790 if (!num_samp[TOP] && !num_samp[LEFT]) {
77 642 return 0;
78 }
79
2/2
✓ Branch 0 taken 123148 times.
✓ Branch 1 taken 61574 times.
369444 for (int i = TOP; i <= LEFT; i++) {
80 246296 const int start = num_samp[i] >> (2 + num_is4);
81 246296 const int step = FFMAX(1, num_samp[i] >> (1 + num_is4)) ;
82 246296 cnt[i] = FFMIN(num_samp[i], (1 + num_is4) << 1);
83
2/2
✓ Branch 0 taken 245960 times.
✓ Branch 1 taken 123148 times.
738216 for (int c = 0; c < cnt[i]; c++)
84 491920 pos[i][c] = start + c * step;
85 }
86 123148 return 1;
87 }
88
89 40208 static av_always_inline void FUNC(cclm_select_luma_444)(const pixel *src, const int step,
90 const int cnt, const int pos[MAX_PICK_POS], pixel *sel_luma)
91 {
92
2/2
✓ Branch 0 taken 40208 times.
✓ Branch 1 taken 20104 times.
120624 for (int i = 0; i < cnt; i++)
93 80416 sel_luma[i] = src[pos[i] * step];
94 40208 }
95
96 123148 static av_always_inline void FUNC(cclm_select_luma)(const VVCFrameContext *fc,
97 const int x0, const int y0, const int avail_t, const int avail_l, const int cnt[2], const int pos[2][MAX_PICK_POS],
98 pixel *sel_luma)
99 {
100 123148 const VVCSPS *sps = fc->ps.sps;
101
102 123148 const int b_ctu_boundary = !av_zero_extend(y0, sps->ctb_log2_size_y);
103 123148 const int hs = sps->hshift[1];
104 123148 const int vs = sps->vshift[1];
105 123148 const ptrdiff_t stride = fc->frame->linesize[0] / sizeof(pixel);
106
107
3/4
✓ Branch 0 taken 10052 times.
✓ Branch 1 taken 51522 times.
✓ Branch 2 taken 10052 times.
✗ Branch 3 not taken.
143252 if (!hs && !vs) {
108 20104 const pixel* src = (pixel*)fc->frame->data[0] + x0 + y0 * stride;
109 20104 FUNC(cclm_select_luma_444)(src - avail_t * stride, 1, cnt[TOP], pos[TOP], sel_luma);
110 20104 FUNC(cclm_select_luma_444)(src - avail_l, stride, cnt[LEFT], pos[LEFT], sel_luma + cnt[TOP]);
111 } else {
112 // top
113
3/4
✓ Branch 0 taken 51522 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43415 times.
✓ Branch 3 taken 8107 times.
189874 if (vs && !b_ctu_boundary) {
114 86830 const pixel *source = (pixel *)fc->frame->data[0] + x0 + (y0 - 2) * stride;
115
2/2
✓ Branch 0 taken 91384 times.
✓ Branch 1 taken 43415 times.
269598 for (int i = 0; i < cnt[TOP]; i++) {
116 182768 const int x = pos[TOP][i] << hs;
117 182768 const pixel *src = source + x;
118
4/4
✓ Branch 0 taken 1355 times.
✓ Branch 1 taken 90029 times.
✓ Branch 2 taken 1242 times.
✓ Branch 3 taken 113 times.
182768 const int has_left = x || avail_l;
119
2/2
✓ Branch 0 taken 91271 times.
✓ Branch 1 taken 113 times.
182768 const pixel l = has_left ? POS(-1, 0) : POS(0, 0);
120
2/2
✓ Branch 0 taken 3536 times.
✓ Branch 1 taken 87848 times.
182768 if (sps->r->sps_chroma_vertical_collocated_flag) {
121 7072 sel_luma[i] = (POS(0, -1) + l + 4 * POS(0, 0) + POS(1, 0) + POS(0, 1) + 4) >> 3;
122 } else {
123
2/2
✓ Branch 0 taken 87735 times.
✓ Branch 1 taken 113 times.
175696 const pixel l1 = has_left ? POS(-1, 1) : POS(0, 1);
124 175696 sel_luma[i] = (l + l1 + 2 * (POS(0, 0) + POS(0, 1)) + POS(1, 0) + POS(1, 1) + 4) >> 3;
125 }
126 }
127 } else {
128 16214 const pixel *source = (pixel*)fc->frame->data[0] + x0 + (y0 - 1) * stride;
129
2/2
✓ Branch 0 taken 12712 times.
✓ Branch 1 taken 8107 times.
41638 for (int i = 0; i < cnt[TOP]; i++) {
130 25424 const int x = pos[TOP][i] << hs;
131 25424 const pixel *src = source + x;
132
4/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 12691 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 19 times.
25424 const int has_left = x || avail_l;
133
2/2
✓ Branch 0 taken 12693 times.
✓ Branch 1 taken 19 times.
25424 const pixel l = has_left ? POS(-1, 0) : POS(0, 0);
134 25424 sel_luma[i] = (l + 2 * POS(0, 0) + POS(1, 0) + 2) >> 2;
135 }
136 }
137
138 // left
139 {
140 const pixel *left;
141 103044 const pixel *source = (pixel *)fc->frame->data[0] + x0 + y0 * stride - (1 + hs) * avail_l;
142 103044 left = source - avail_l;
143
144
2/2
✓ Branch 0 taken 101656 times.
✓ Branch 1 taken 51522 times.
306356 for (int i = 0; i < cnt[LEFT]; i++) {
145 203312 const int y = pos[LEFT][i] << vs;
146 203312 const int offset = y * stride;
147 203312 const pixel *l = left + offset;
148 203312 const pixel *src = source + offset;
149 pixel pred;
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101656 times.
203312 if (!vs) {
151 pred = (*l + 2 * POS(0, 0) + POS(1, 0) + 2) >> 2;
152 } else {
153
2/2
✓ Branch 0 taken 4884 times.
✓ Branch 1 taken 96772 times.
203312 if (sps->r->sps_chroma_vertical_collocated_flag) {
154
3/4
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 4794 times.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
9768 const int has_top = y || avail_t;
155
1/2
✓ Branch 0 taken 4884 times.
✗ Branch 1 not taken.
9768 const pixel t = has_top ? POS(0, -1) : POS(0, 0);
156 9768 pred = (*l + t + 4 * POS(0, 0) + POS(1, 0) + POS(0, 1) + 4) >> 3;
157 } else {
158 193544 pred = (*l + *(l + stride) + 2 * POS(0, 0) + 2 * POS(0, 1) + POS(1, 0) + POS(1, 1) + 4) >> 3;
159 }
160 }
161 203312 sel_luma[i + cnt[TOP]] = pred;
162 }
163 }
164 }
165 123148 }
166
167 123148 static av_always_inline void FUNC(cclm_select_chroma)(const VVCFrameContext *fc,
168 const int x, const int y, const int cnt[2], const int pos[2][MAX_PICK_POS],
169 pixel sel[][MAX_PICK_POS * 2])
170 {
171
2/2
✓ Branch 0 taken 123148 times.
✓ Branch 1 taken 61574 times.
369444 for (int c_idx = 1; c_idx < VVC_MAX_SAMPLE_ARRAYS; c_idx++) {
172 246296 const ptrdiff_t stride = fc->frame->linesize[c_idx] / sizeof(pixel);
173
174 //top
175 246296 const pixel *src = (pixel*)fc->frame->data[c_idx] + x + (y - 1)* stride;
176
2/2
✓ Branch 0 taken 249464 times.
✓ Branch 1 taken 123148 times.
745224 for (int i = 0; i < cnt[TOP]; i++) {
177 498928 sel[c_idx][i] = src[pos[TOP][i]];
178 }
179
180 //left
181 246296 src = (pixel*)fc->frame->data[c_idx] + x - 1 + y * stride;
182
2/2
✓ Branch 0 taken 242456 times.
✓ Branch 1 taken 123148 times.
731208 for (int i = 0; i < cnt[LEFT]; i++) {
183 484912 sel[c_idx][i + cnt[TOP]] = src[pos[LEFT][i] * stride];
184 }
185 }
186 123148 }
187
188 123790 static av_always_inline int FUNC(cclm_select_samples)(const VVCLocalContext *lc,
189 const int x0, const int y0, const int w, const int h, const int avail_t, const int avail_l,
190 pixel sel[][MAX_PICK_POS * 2])
191 {
192 123790 const VVCFrameContext *fc = lc->fc;
193 123790 const VVCSPS *sps = fc->ps.sps;
194 123790 const int x = x0 >> sps->hshift[1];
195 123790 const int y = y0 >> sps->vshift[1];
196 int cnt[2], pos[2][MAX_PICK_POS];
197
198
2/2
✓ Branch 1 taken 321 times.
✓ Branch 2 taken 61574 times.
123790 if (!FUNC(cclm_get_select_pos)(lc, x, y, w, h, avail_t, avail_l, cnt, pos))
199 642 return 0;
200
201 123148 FUNC(cclm_select_luma)(fc, x0, y0, avail_t, avail_l, cnt, pos, sel[LUMA]);
202 123148 FUNC(cclm_select_chroma)(fc, x, y, cnt, pos, sel);
203
204
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 61406 times.
123148 if (cnt[TOP] + cnt[LEFT] == 2) {
205
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
1344 for (int c_idx = 0; c_idx < VVC_MAX_SAMPLE_ARRAYS; c_idx++) {
206 1008 sel[c_idx][3] = sel[c_idx][0];
207 1008 sel[c_idx][2] = sel[c_idx][1];
208 1008 sel[c_idx][0] = sel[c_idx][1];
209 1008 sel[c_idx][1] = sel[c_idx][3];
210 }
211 }
212 123148 return 1;
213 }
214
215 123148 static av_always_inline void FUNC(cclm_get_min_max)(
216 const pixel sel[][MAX_PICK_POS * 2], int *min, int *max)
217 {
218 123148 int min_grp_idx[] = { 0, 2 };
219 123148 int max_grp_idx[] = { 1, 3 };
220
221
2/2
✓ Branch 0 taken 30068 times.
✓ Branch 1 taken 31506 times.
123148 if (sel[LUMA][min_grp_idx[0]] > sel[LUMA][min_grp_idx[1]])
222 60136 FFSWAP(int, min_grp_idx[0], min_grp_idx[1]);
223
2/2
✓ Branch 0 taken 30559 times.
✓ Branch 1 taken 31015 times.
123148 if (sel[LUMA][max_grp_idx[0]] > sel[LUMA][max_grp_idx[1]])
224 61118 FFSWAP(int, max_grp_idx[0], max_grp_idx[1]);
225
2/2
✓ Branch 0 taken 6371 times.
✓ Branch 1 taken 55203 times.
123148 if (sel[LUMA][min_grp_idx[0]] > sel[LUMA][max_grp_idx[1]]) {
226 12742 FFSWAP(int, min_grp_idx[0], max_grp_idx[0]);
227 12742 FFSWAP(int, min_grp_idx[1], max_grp_idx[1]);
228 }
229
2/2
✓ Branch 0 taken 47392 times.
✓ Branch 1 taken 14182 times.
123148 if (sel[LUMA][min_grp_idx[1]] > sel[LUMA][max_grp_idx[0]])
230 94784 FFSWAP(int, min_grp_idx[1], max_grp_idx[0]);
231
2/2
✓ Branch 0 taken 184722 times.
✓ Branch 1 taken 61574 times.
492592 for (int c_idx = 0; c_idx < VVC_MAX_SAMPLE_ARRAYS; c_idx++) {
232 369444 max[c_idx] = (sel[c_idx][max_grp_idx[0]] + sel[c_idx][max_grp_idx[1]] + 1) >> 1;
233 369444 min[c_idx] = (sel[c_idx][min_grp_idx[0]] + sel[c_idx][min_grp_idx[1]] + 1) >> 1;
234 }
235 123148 }
236
237 123790 static av_always_inline void FUNC(cclm_get_params)(const VVCLocalContext *lc,
238 const int x0, const int y0, const int w, const int h, const int avail_t, const int avail_l,
239 int *a, int *b, int *k)
240 {
241 pixel sel[VVC_MAX_SAMPLE_ARRAYS][MAX_PICK_POS * 2];
242 int max[VVC_MAX_SAMPLE_ARRAYS], min[VVC_MAX_SAMPLE_ARRAYS];
243 int diff;
244
245
2/2
✓ Branch 1 taken 321 times.
✓ Branch 2 taken 61574 times.
123790 if (!FUNC(cclm_select_samples)(lc, x0, y0, w, h, avail_t, avail_l, sel)) {
246 642 FUNC(cclm_get_params_default)(a, b, k);
247 3138 return;
248 }
249
250 123148 FUNC(cclm_get_min_max)(sel, min, max);
251
252 123148 diff = max[LUMA] - min[LUMA];
253
2/2
✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 60326 times.
123148 if (diff == 0) {
254
2/2
✓ Branch 0 taken 2496 times.
✓ Branch 1 taken 1248 times.
7488 for (int i = 0; i < 2; i++) {
255 4992 a[i] = k[i] = 0;
256 4992 b[i] = min[i + 1];
257 }
258 2496 return;
259 }
260
2/2
✓ Branch 0 taken 120652 times.
✓ Branch 1 taken 60326 times.
361956 for (int i = 0; i < 2; i++) {
261 const static int div_sig_table[] = {0, 7, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 1, 0};
262 241304 const int diffc = max[i + 1] - min[i + 1];
263 241304 int x = av_log2(diff);
264 int y, v, sign, add;
265 241304 const int norm_diff = ((diff << 4) >> x) & 15;
266 241304 x += (norm_diff) ? 1 : 0;
267
2/2
✓ Branch 0 taken 109214 times.
✓ Branch 1 taken 11438 times.
241304 y = abs(diffc) > 0 ? av_log2(abs(diffc)) + 1 : 0;
268 241304 v = div_sig_table[norm_diff] | 8;
269 241304 add = (1 << y >> 1);
270 241304 a[i] = (diffc * v + add) >> y;
271 241304 k[i] = FFMAX(1, 3 + x -y);
272
2/2
✓ Branch 0 taken 51644 times.
✓ Branch 1 taken 69008 times.
241304 sign = a[i] < 0 ? -1 : (a[i] > 0);
273
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 120590 times.
241304 a[i] = ((3 + x - y) < 1) ? sign * 15 : a[i];
274 241304 b[i] = min[i + 1] - ((a[i] * min[0]) >> k[i]);
275 }
276
277 }
278
279 #undef TOP
280 #undef LEFT
281
282 123790 static av_always_inline void FUNC(cclm_get_luma_rec_pixels)(const VVCFrameContext *fc,
283 const int x0, const int y0, const int w, const int h, const int avail_t, const int avail_l,
284 pixel *pdsy)
285 {
286 123790 const int hs = fc->ps.sps->hshift[1];
287 123790 const int vs = fc->ps.sps->vshift[1];
288 123790 const ptrdiff_t stride = fc->frame->linesize[0] / sizeof(pixel);
289 123790 const pixel *source = (pixel*)fc->frame->data[0] + x0 + y0 * stride;
290 123790 const pixel *left = source - avail_l;
291 123790 const pixel *top = source - avail_t * stride;
292
293 123790 const VVCSPS *sps = fc->ps.sps;
294
3/4
✓ Branch 0 taken 10054 times.
✓ Branch 1 taken 51841 times.
✓ Branch 2 taken 10054 times.
✗ Branch 3 not taken.
123790 if (!hs && !vs) {
295
2/2
✓ Branch 0 taken 137736 times.
✓ Branch 1 taken 10054 times.
295580 for (int i = 0; i < h; i++)
296 275472 memcpy(pdsy + i * w, source + i * stride, w * sizeof(pixel));
297 20108 return;
298 }
299
2/2
✓ Branch 0 taken 492046 times.
✓ Branch 1 taken 51841 times.
1087774 for (int i = 0; i < h; i++) {
300 984092 const pixel *src = source;
301 984092 const pixel *l = left;
302 984092 const pixel *t = top;
303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 492046 times.
984092 if (!vs) {
304 for (int j = 0; j < w; j++) {
305 pixel pred = (*l + 2 * POS(0, 0) + POS(1, 0) + 2) >> 2;
306 pdsy[i * w + j] = pred;
307 src += 2;
308 l = src - 1;
309 }
310
311 } else {
312
2/2
✓ Branch 0 taken 41022 times.
✓ Branch 1 taken 451024 times.
984092 if (sps->r->sps_chroma_vertical_collocated_flag) {
313
2/2
✓ Branch 0 taken 1001008 times.
✓ Branch 1 taken 41022 times.
2084060 for (int j = 0; j < w; j++) {
314 2002016 pixel pred = (*l + *t + 4 * POS(0, 0) + POS(1, 0) + POS(0, 1) + 4) >> 3;
315 2002016 pdsy[i * w + j] = pred;
316 2002016 src += 2;
317 2002016 t += 2;
318 2002016 l = src - 1;
319 }
320 } else {
321
2/2
✓ Branch 0 taken 6534480 times.
✓ Branch 1 taken 451024 times.
13971008 for (int j = 0; j < w; j++) {
322 13068960 pixel pred = (*l + *(l + stride) + 2 * POS(0, 0) + 2 * POS(0, 1) + POS(1, 0) + POS(1, 1) + 4) >> 3;
323
324 13068960 pdsy[i * w + j] = pred;
325 13068960 src += 2;
326 13068960 l = src - 1;
327 }
328 }
329 }
330 984092 source += (stride << vs);
331 984092 left += (stride << vs);
332 984092 top = source - stride;
333 }
334 }
335
336 392 static av_always_inline void FUNC(cclm_pred_default)(VVCFrameContext *fc,
337 const int x, const int y, const int w, const int h, const int avail_t, const int avail_l)
338 {
339
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 196 times.
1176 for (int c_idx = 1; c_idx < VVC_MAX_SAMPLE_ARRAYS; c_idx++) {
340 784 const ptrdiff_t stride = fc->frame->linesize[c_idx] / sizeof(pixel);
341 784 pixel *dst = (pixel*)fc->frame->data[c_idx] + x + y * stride;
342
2/2
✓ Branch 0 taken 7848 times.
✓ Branch 1 taken 392 times.
16480 for (int i = 0; i < h; i++) {
343
2/2
✓ Branch 0 taken 215680 times.
✓ Branch 1 taken 7848 times.
447056 for (int j = 0; j < w; j++) {
344 431360 dst[j] = 1 << (BIT_DEPTH - 1);
345 }
346 15696 dst += stride;
347 }
348 }
349 392 }
350
351 //8.4.5.2.14 Specification of INTRA_LT_CCLM, INTRA_L_CCLM and INTRA_T_CCLM intra prediction mode
352 124182 static void FUNC(intra_cclm_pred)(const VVCLocalContext *lc, const int x0, const int y0,
353 const int width, const int height)
354 {
355 124182 VVCFrameContext *fc = lc->fc;
356 124182 const VVCSPS *sps = fc->ps.sps;
357 124182 const int avail_t = ff_vvc_get_top_available(lc, x0, y0, 1, 0);
358 124182 const int avail_l = ff_vvc_get_left_available(lc, x0, y0, 1, 0);
359 124182 const int hs = sps->hshift[1];
360 124182 const int vs = sps->vshift[1];
361 124182 const int x = x0 >> hs;
362 124182 const int y = y0 >> vs;
363 124182 const int w = width >> hs;
364 124182 const int h = height >> vs;
365 int a[2], b[2], k[2];
366
367 pixel dsy[MAX_TB_SIZE * MAX_TB_SIZE];
368
4/4
✓ Branch 0 taken 2432 times.
✓ Branch 1 taken 59659 times.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 2236 times.
124182 if (!avail_t && !avail_l) {
369 392 FUNC(cclm_pred_default)(fc, x, y, w, h, avail_t, avail_l);
370 392 return;
371 }
372 123790 FUNC(cclm_get_luma_rec_pixels)(fc, x0, y0, w, h, avail_t, avail_l, dsy);
373 123790 FUNC(cclm_get_params) (lc, x0, y0, w, h, avail_t, avail_l, a, b, k);
374 123790 FUNC(cclm_linear_pred)(fc, x0, y0, w, h, dsy, a, b, k);
375 }
376
377 29772 static int FUNC(lmcs_sum_samples)(const pixel *start, ptrdiff_t stride, const int avail, const int target_size)
378 {
379 29772 const int size = FFMIN(avail, target_size);
380 29772 int sum = 0;
381
2/2
✓ Branch 0 taken 938624 times.
✓ Branch 1 taken 14886 times.
1907020 for (int i = 0; i < size; i++) {
382 1877248 sum += *start;
383 1877248 start += stride;
384 }
385 29772 sum += *(start - stride) * (target_size - size);
386 29772 return sum;
387 }
388
389 // 8.7.5.3 Picture reconstruction with luma dependent chroma residual scaling process for chroma samples
390 173888 static int FUNC(lmcs_derive_chroma_scale)(VVCLocalContext *lc, const int x0, const int y0)
391 {
392 173888 VVCFrameContext *fc = lc->fc;
393 173888 const VVCLMCS *lmcs = &fc->ps.lmcs;
394 173888 const int size_y = FFMIN(fc->ps.sps->ctb_size_y, 64);
395
396 173888 const int x = x0 & ~(size_y - 1);
397 173888 const int y = y0 & ~(size_y - 1);
398
4/4
✓ Branch 0 taken 79250 times.
✓ Branch 1 taken 7694 times.
✓ Branch 2 taken 643 times.
✓ Branch 3 taken 78607 times.
173888 if (lc->lmcs.x_vpdu != x || lc->lmcs.y_vpdu != y) {
399 16674 int cnt = 0, luma = 0, i;
400 16674 const pixel *src = (const pixel *)(fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift));
401 16674 const ptrdiff_t stride = fc->frame->linesize[LUMA] / sizeof(pixel);
402 16674 const int avail_t = ff_vvc_get_top_available (lc, x, y, 1, 0);
403 16674 const int avail_l = ff_vvc_get_left_available(lc, x, y, 1, 0);
404
2/2
✓ Branch 0 taken 7673 times.
✓ Branch 1 taken 664 times.
16674 if (avail_l) {
405 15346 luma += FUNC(lmcs_sum_samples)(src - 1, stride, fc->ps.pps->height - y, size_y);
406 15346 cnt = size_y;
407 }
408
2/2
✓ Branch 0 taken 7213 times.
✓ Branch 1 taken 1124 times.
16674 if (avail_t) {
409 14426 luma += FUNC(lmcs_sum_samples)(src - stride, 1, fc->ps.pps->width - x, size_y);
410 14426 cnt += size_y;
411 }
412
2/2
✓ Branch 0 taken 8189 times.
✓ Branch 1 taken 148 times.
16674 if (cnt)
413 16378 luma = (luma + (cnt >> 1)) >> av_log2(cnt);
414 else
415 296 luma = 1 << (BIT_DEPTH - 1);
416
417
1/2
✓ Branch 0 taken 52606 times.
✗ Branch 1 not taken.
105212 for (i = lmcs->min_bin_idx; i <= lmcs->max_bin_idx; i++) {
418
2/2
✓ Branch 0 taken 8337 times.
✓ Branch 1 taken 44269 times.
105212 if (luma < lmcs->pivot[i + 1])
419 16674 break;
420 }
421 16674 i = FFMIN(i, LMCS_MAX_BIN_SIZE - 1);
422
423 16674 lc->lmcs.chroma_scale = lmcs->chroma_scale_coeff[i];
424 16674 lc->lmcs.x_vpdu = x;
425 16674 lc->lmcs.y_vpdu = y;
426 }
427 173888 return lc->lmcs.chroma_scale;
428 }
429
430 // 8.7.5.3 Picture reconstruction with luma dependent chroma residual scaling process for chroma samples
431 173888 static void FUNC(lmcs_scale_chroma)(VVCLocalContext *lc, int *dst, const int *coeff,
432 const int width, const int height, const int x0_cu, const int y0_cu)
433 {
434 173888 const int chroma_scale = FUNC(lmcs_derive_chroma_scale)(lc, x0_cu, y0_cu);
435
436
2/2
✓ Branch 0 taken 1007942 times.
✓ Branch 1 taken 86944 times.
2189772 for (int y = 0; y < height; y++) {
437
2/2
✓ Branch 0 taken 16874568 times.
✓ Branch 1 taken 1007942 times.
35765020 for (int x = 0; x < width; x++) {
438 33749136 const int c = av_clip_intp2(*coeff, BIT_DEPTH);
439
440
2/2
✓ Branch 0 taken 7335381 times.
✓ Branch 1 taken 9539187 times.
33749136 if (c > 0)
441 14670762 *dst = (c * chroma_scale + (1 << 10)) >> 11;
442 else
443 19078374 *dst = -((-c * chroma_scale + (1 << 10)) >> 11);
444 33749136 coeff++;
445 33749136 dst++;
446 }
447 }
448 173888 }
449
450 185880 static av_always_inline void FUNC(ref_filter)(const pixel *left, const pixel *top,
451 pixel *filtered_left, pixel *filtered_top, const int left_size, const int top_size,
452 const int unfilter_last_one)
453 {
454 185880 filtered_left[-1] = filtered_top[-1] = (left[0] + 2 * left[-1] + top[0] + 2 ) >> 2;
455
2/2
✓ Branch 0 taken 1576914 times.
✓ Branch 1 taken 92940 times.
3339708 for (int i = 0; i < left_size - unfilter_last_one; i++) {
456 3153828 filtered_left[i] = (left[i- 1] + 2 * left[i] + left[i + 1] + 2) >> 2;
457 }
458
2/2
✓ Branch 0 taken 1812138 times.
✓ Branch 1 taken 92940 times.
3810156 for (int i = 0; i < top_size - unfilter_last_one; i++) {
459 3624276 filtered_top[i] = (top[i-1] + 2 * top[i] + top[i + 1] + 2) >> 2;
460 }
461
2/2
✓ Branch 0 taken 3766 times.
✓ Branch 1 taken 89174 times.
185880 if (unfilter_last_one) {
462 7532 filtered_top[top_size - 1] = top[top_size - 1];
463 7532 filtered_left[left_size - 1] = left[left_size - 1];
464 }
465 185880 }
466
467 1492280 static av_always_inline void FUNC(prepare_intra_edge_params)(const VVCLocalContext *lc,
468 IntraEdgeParams* edge, const pixel *src, const ptrdiff_t stride,
469 const int x, int y, int w, int h, int c_idx, const int is_intra_mip,
470 const int mode, const int ref_idx, const int need_pdpc)
471 {
472 #define EXTEND(ptr, val, len) \
473 do { \
474 for (i = 0; i < (len); i++) \
475 *(ptr + i) = val; \
476 } while (0)
477 1492280 const CodingUnit *cu = lc->cu;
478
2/2
✓ Branch 0 taken 670901 times.
✓ Branch 1 taken 75239 times.
1492280 const int ref_filter_flag = is_intra_mip ? 0 : ff_vvc_ref_filter_flag_derive(mode);
479
4/4
✓ Branch 0 taken 401437 times.
✓ Branch 1 taken 321840 times.
✓ Branch 2 taken 282061 times.
✓ Branch 3 taken 119376 times.
1446554 const int filter_flag = !ref_idx && w * h > 32 && !c_idx &&
480
6/6
✓ Branch 0 taken 723277 times.
✓ Branch 1 taken 22863 times.
✓ Branch 2 taken 235466 times.
✓ Branch 3 taken 46595 times.
✓ Branch 4 taken 92940 times.
✓ Branch 5 taken 142526 times.
2938834 cu->isp_split_type == ISP_NO_SPLIT && ref_filter_flag;
481 1492280 int cand_up_left = lc->na.cand_up_left;
482 1492280 pixel *left = (pixel*)edge->left_array + MAX_TB_SIZE + 3;
483 1492280 pixel *top = (pixel*)edge->top_array + MAX_TB_SIZE + 3;
484 1492280 pixel *filtered_left = (pixel*)edge->filtered_left_array + MAX_TB_SIZE + 3;
485 1492280 pixel *filtered_top = (pixel*)edge->filtered_top_array + MAX_TB_SIZE + 3;
486 1492280 const int ref_line = ref_idx == 3 ? -4 : (-1 - ref_idx);
487 int left_size, top_size, unfilter_left_size, unfilter_top_size;
488 int left_available, top_available;
489 int refw, refh;
490 int intra_pred_angle, inv_angle;
491 int i;
492
493
4/4
✓ Branch 0 taken 670901 times.
✓ Branch 1 taken 75239 times.
✓ Branch 2 taken 283591 times.
✓ Branch 3 taken 387310 times.
1492280 if (is_intra_mip || mode == INTRA_PLANAR) {
494 717660 left_size = h + 1;
495 717660 top_size = w + 1;
496 717660 unfilter_left_size = left_size + filter_flag;
497 717660 unfilter_top_size = top_size + filter_flag;
498
2/2
✓ Branch 0 taken 45737 times.
✓ Branch 1 taken 341573 times.
774620 } else if (mode == INTRA_DC) {
499 91474 unfilter_left_size = left_size = h;
500 91474 unfilter_top_size = top_size = w;
501
2/2
✓ Branch 0 taken 36038 times.
✓ Branch 1 taken 305535 times.
683146 } else if (mode == INTRA_VERT) {
502 //we may need 1 pixel to predict the top left.
503
2/2
✓ Branch 0 taken 31549 times.
✓ Branch 1 taken 4489 times.
72076 unfilter_left_size = left_size = need_pdpc ? h : 1;
504 72076 unfilter_top_size = top_size = w;
505
2/2
✓ Branch 0 taken 34423 times.
✓ Branch 1 taken 271112 times.
611070 } else if (mode == INTRA_HORZ) {
506 68846 unfilter_left_size = left_size = h;
507 //even need_pdpc == 0, we may need 1 pixel to predict the top left.
508
2/2
✓ Branch 0 taken 27160 times.
✓ Branch 1 taken 7263 times.
68846 unfilter_top_size = top_size = need_pdpc ? w : 1;
509 } else {
510
4/4
✓ Branch 0 taken 71618 times.
✓ Branch 1 taken 199494 times.
✓ Branch 2 taken 2868 times.
✓ Branch 3 taken 68750 times.
542224 if (cu->isp_split_type == ISP_NO_SPLIT || c_idx) {
511 404724 refw = w * 2;
512 404724 refh = h * 2;
513 } else {
514 137500 refw = cu->cb_width + w;
515 137500 refh = cu->cb_height + h;
516 }
517 542224 intra_pred_angle = ff_vvc_intra_pred_angle_derive(mode);
518 542224 inv_angle = ff_vvc_intra_inv_angle_derive(intra_pred_angle);
519 542224 unfilter_top_size = top_size = refw;
520 542224 unfilter_left_size = left_size = refh;
521 }
522
523 1492280 left_available = ff_vvc_get_left_available(lc, x, y, unfilter_left_size, c_idx);
524
2/2
✓ Branch 0 taken 8140446 times.
✓ Branch 1 taken 746140 times.
17773172 for (i = 0; i < left_available; i++)
525 16280892 left[i] = POS(ref_line, i);
526
527 1492280 top_available = ff_vvc_get_top_available(lc, x, y, unfilter_top_size, c_idx);
528 1492280 memcpy(top, src + ref_line * stride, top_available * sizeof(pixel));
529
530
2/2
✓ Branch 0 taken 783397 times.
✓ Branch 1 taken 746140 times.
3059074 for (int i = -1; i >= ref_line; i--) {
531
2/2
✓ Branch 0 taken 750107 times.
✓ Branch 1 taken 33290 times.
1566794 if (cand_up_left) {
532 1500214 left[i] = POS(ref_line, i);
533 1500214 top[i] = POS(i, ref_line);
534
2/2
✓ Branch 0 taken 15382 times.
✓ Branch 1 taken 17908 times.
66580 } else if (left_available) {
535 30764 left[i] = top[i] = left[0];
536
2/2
✓ Branch 0 taken 17300 times.
✓ Branch 1 taken 608 times.
35816 } else if (top_available) {
537 34600 left[i] = top[i] = top[0];
538 } else {
539 1216 left[i] = top[i] = 1 << (BIT_DEPTH - 1);
540 }
541 }
542
543
2/2
✓ Branch 0 taken 2705426 times.
✓ Branch 1 taken 746140 times.
6903132 EXTEND(top + top_available, top[top_available-1], unfilter_top_size - top_available);
544
2/2
✓ Branch 0 taken 2015127 times.
✓ Branch 1 taken 746140 times.
5522534 EXTEND(left + left_available, left[left_available-1], unfilter_left_size - left_available);
545
546
2/2
✓ Branch 0 taken 299927 times.
✓ Branch 1 taken 446213 times.
1492280 if (ref_filter_flag) {
547
8/8
✓ Branch 0 taken 299427 times.
✓ Branch 1 taken 500 times.
✓ Branch 2 taken 177892 times.
✓ Branch 3 taken 121535 times.
✓ Branch 4 taken 115634 times.
✓ Branch 5 taken 62258 times.
✓ Branch 6 taken 92940 times.
✓ Branch 7 taken 22694 times.
599854 if (!ref_idx && w * h > 32 && !c_idx && cu->isp_split_type == ISP_NO_SPLIT ) {
548 185880 const int unfilter_last_one = left_size == unfilter_left_size;
549 185880 FUNC(ref_filter)(left, top, filtered_left, filtered_top, unfilter_left_size, unfilter_top_size, unfilter_last_one);
550 185880 left = filtered_left;
551 185880 top = filtered_top;
552 }
553 }
554
6/6
✓ Branch 0 taken 670901 times.
✓ Branch 1 taken 75239 times.
✓ Branch 2 taken 387310 times.
✓ Branch 3 taken 283591 times.
✓ Branch 4 taken 341573 times.
✓ Branch 5 taken 45737 times.
1492280 if (!is_intra_mip && mode != INTRA_PLANAR && mode != INTRA_DC) {
555
6/6
✓ Branch 0 taken 325237 times.
✓ Branch 1 taken 16336 times.
✓ Branch 2 taken 305881 times.
✓ Branch 3 taken 19356 times.
✓ Branch 4 taken 85068 times.
✓ Branch 5 taken 220813 times.
683146 if (ref_filter_flag || ref_idx || cu->isp_split_type != ISP_NO_SPLIT) {
556 241520 edge->filter_flag = 0;
557 } else {
558 441626 const int min_dist_ver_hor = FFMIN(abs(mode - 50), abs(mode - 18));
559 441626 const int intra_hor_ver_dist_thres[] = {24, 14, 2, 0, 0};
560 441626 const int ntbs = (av_log2(w) + av_log2(h)) >> 1;
561 441626 edge->filter_flag = min_dist_ver_hor > intra_hor_ver_dist_thres[ntbs - 2];
562 }
563
564
4/4
✓ Branch 0 taken 305535 times.
✓ Branch 1 taken 36038 times.
✓ Branch 2 taken 271112 times.
✓ Branch 3 taken 34423 times.
683146 if (mode != INTRA_VERT && mode != INTRA_HORZ) {
565
2/2
✓ Branch 0 taken 139915 times.
✓ Branch 1 taken 131197 times.
542224 if (mode >= INTRA_DIAG) {
566
2/2
✓ Branch 0 taken 73182 times.
✓ Branch 1 taken 66733 times.
279830 if (intra_pred_angle < 0) {
567 146364 pixel *p = top - (ref_idx + 1);
568
2/2
✓ Branch 0 taken 624976 times.
✓ Branch 1 taken 73182 times.
1396316 for (int x = -h; x < 0; x++) {
569 1249952 const int idx = -1 - ref_idx + FFMIN((x*inv_angle + 256) >> 9, h);
570 1249952 p[x] = left[idx];
571 }
572 } else {
573
2/2
✓ Branch 0 taken 143093 times.
✓ Branch 1 taken 66733 times.
419652 for (int i = refw; i <= refw + FFMAX(1, w/h) * ref_idx + 1; i++)
574 286186 top[i] = top[refw - 1];
575 }
576 } else {
577
2/2
✓ Branch 0 taken 71229 times.
✓ Branch 1 taken 59968 times.
262394 if (intra_pred_angle < 0) {
578 142458 pixel *p = left - (ref_idx + 1);
579
2/2
✓ Branch 0 taken 1147144 times.
✓ Branch 1 taken 71229 times.
2436746 for (int x = -w; x < 0; x++) {
580 2294288 const int idx = -1 - ref_idx + FFMIN((x*inv_angle + 256) >> 9, w);
581 2294288 p[x] = top[idx];
582 }
583 } else {
584
2/2
✓ Branch 0 taken 128981 times.
✓ Branch 1 taken 59968 times.
377898 for (int i = refh; i <= refh + FFMAX(1, h/w) * ref_idx + 1; i++)
585 257962 left[i] = left[refh - 1];
586 }
587 }
588 }
589 }
590 1492280 edge->left = (uint8_t*)left;
591 1492280 edge->top = (uint8_t*)top;
592 1492280 }
593
594 //8.4.1 General decoding process for coding units coded in intra prediction mode
595 1492280 static void FUNC(intra_pred)(const VVCLocalContext *lc, int x0, int y0,
596 const int width, const int height, int c_idx)
597 {
598 1492280 VVCFrameContext *fc = lc->fc;
599 1492280 const VVCSPS *sps = fc->ps.sps;
600 1492280 const VVCPPS *pps = fc->ps.pps;
601 1492280 const CodingUnit *cu = lc->cu;
602 1492280 const int log2_min_cb_size = sps->min_cb_log2_size_y;
603 1492280 const int min_cb_width = pps->min_cb_width;
604 1492280 const int x_cb = x0 >> log2_min_cb_size;
605 1492280 const int y_cb = y0 >> log2_min_cb_size;
606
607 1492280 const int hshift = fc->ps.sps->hshift[c_idx];
608 1492280 const int vshift = fc->ps.sps->vshift[c_idx];
609 1492280 const int x = x0 >> hshift;
610 1492280 const int y = y0 >> vshift;
611 1492280 const int w = width >> hshift;
612 1492280 const int h = height >> vshift;
613 1492280 const ptrdiff_t stride = fc->frame->linesize[c_idx] / sizeof(pixel);
614
615
2/2
✓ Branch 0 taken 218382 times.
✓ Branch 1 taken 527758 times.
1492280 const int pred_mode = c_idx ? cu->intra_pred_mode_c : cu->intra_pred_mode_y;
616 1492280 const int mode = ff_vvc_wide_angle_mode_mapping(cu, w, h, c_idx, pred_mode);
617
618 1492280 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
619
6/6
✓ Branch 0 taken 113103 times.
✓ Branch 1 taken 633037 times.
✓ Branch 2 taken 38152 times.
✓ Branch 3 taken 74951 times.
✓ Branch 4 taken 288 times.
✓ Branch 5 taken 37864 times.
1492280 const int is_intra_mip = intra_mip_flag && (!c_idx || cu->mip_chroma_direct_flag);
620
2/2
✓ Branch 0 taken 527758 times.
✓ Branch 1 taken 218382 times.
1492280 const int ref_idx = c_idx ? 0 : cu->intra_luma_ref_idx;
621 1492280 const int need_pdpc = ff_vvc_need_pdpc(w, h, cu->bdpcm_flag[c_idx], mode, ref_idx);
622
623
624 1492280 pixel *src = (pixel*)fc->frame->data[c_idx] + x + y * stride;
625 IntraEdgeParams edge;
626
627 1492280 FUNC(prepare_intra_edge_params)(lc, &edge, src, stride, x, y, w, h, c_idx, is_intra_mip, mode, ref_idx, need_pdpc);
628
629
2/2
✓ Branch 0 taken 75239 times.
✓ Branch 1 taken 670901 times.
1492280 if (is_intra_mip) {
630 150478 int intra_mip_transposed_flag = SAMPLE_CTB(fc->tab.imtf, x_cb, y_cb);
631 150478 int intra_mip_mode = SAMPLE_CTB(fc->tab.imm, x_cb, y_cb);
632
633 150478 fc->vvcdsp.intra.pred_mip((uint8_t *)src, edge.top, edge.left,
634 w, h, stride, intra_mip_mode, intra_mip_transposed_flag);
635
2/2
✓ Branch 0 taken 283591 times.
✓ Branch 1 taken 387310 times.
1341802 } else if (mode == INTRA_PLANAR) {
636 567182 fc->vvcdsp.intra.pred_planar((uint8_t *)src, edge.top, edge.left, w, h, stride);
637
2/2
✓ Branch 0 taken 45737 times.
✓ Branch 1 taken 341573 times.
774620 } else if (mode == INTRA_DC) {
638 91474 fc->vvcdsp.intra.pred_dc((uint8_t *)src, edge.top, edge.left, w, h, stride);
639
2/2
✓ Branch 0 taken 36038 times.
✓ Branch 1 taken 305535 times.
683146 } else if (mode == INTRA_VERT) {
640 72076 fc->vvcdsp.intra.pred_v((uint8_t *)src, edge.top, w, h, stride);
641
2/2
✓ Branch 0 taken 34423 times.
✓ Branch 1 taken 271112 times.
611070 } else if (mode == INTRA_HORZ) {
642 68846 fc->vvcdsp.intra.pred_h((uint8_t *)src, edge.left, w, h, stride);
643 } else {
644
2/2
✓ Branch 0 taken 139915 times.
✓ Branch 1 taken 131197 times.
542224 if (mode >= INTRA_DIAG) {
645 279830 fc->vvcdsp.intra.pred_angular_v((uint8_t *)src, edge.top, edge.left,
646 w, h, stride, c_idx, mode, ref_idx,
647 edge.filter_flag, need_pdpc);
648 } else {
649 262394 fc->vvcdsp.intra.pred_angular_h((uint8_t *)src, edge.top, edge.left,
650 w, h, stride, c_idx, mode, ref_idx,
651 edge.filter_flag, need_pdpc);
652 }
653 }
654
2/2
✓ Branch 0 taken 479462 times.
✓ Branch 1 taken 266678 times.
1492280 if (need_pdpc) {
655 //8.4.5.2.15 Position-dependent intra prediction sample filtering process
656
8/8
✓ Branch 0 taken 413785 times.
✓ Branch 1 taken 65677 times.
✓ Branch 2 taken 156058 times.
✓ Branch 3 taken 257727 times.
✓ Branch 4 taken 116158 times.
✓ Branch 5 taken 39900 times.
✓ Branch 6 taken 84609 times.
✓ Branch 7 taken 31549 times.
958924 if (!is_intra_mip && (mode == INTRA_PLANAR || mode == INTRA_DC ||
657
2/2
✓ Branch 0 taken 27160 times.
✓ Branch 1 taken 57449 times.
169218 mode == INTRA_VERT || mode == INTRA_HORZ)) {
658 712672 const int scale = (av_log2(w) + av_log2(h) - 2) >> 2;
659 712672 const pixel *left = (pixel*)edge.left;
660 712672 const pixel *top = (pixel*)edge.top;
661
2/2
✓ Branch 0 taken 3928796 times.
✓ Branch 1 taken 356336 times.
8570264 for (int y = 0; y < h; y++) {
662
2/2
✓ Branch 0 taken 67439280 times.
✓ Branch 1 taken 3928796 times.
142736152 for (int x = 0; x < w; x++) {
663 int l, t, wl, wt, pred;
664 pixel val;
665
4/4
✓ Branch 0 taken 18899264 times.
✓ Branch 1 taken 48540016 times.
✓ Branch 2 taken 7748096 times.
✓ Branch 3 taken 11151168 times.
134878560 if (mode == INTRA_PLANAR || mode == INTRA_DC) {
666 112576224 l = left[y];
667 112576224 t = top[x];
668 112576224 wl = 32 >> FFMIN((x << 1) >> scale, 31);
669 112576224 wt = 32 >> FFMIN((y << 1) >> scale, 31);
670 } else {
671 22302336 l = left[y] - left[-1] + POS(x,y);
672 22302336 t = top[x] - top[-1] + POS(x,y);
673
2/2
✓ Branch 0 taken 5300592 times.
✓ Branch 1 taken 5850576 times.
22302336 wl = (mode == INTRA_VERT) ? (32 >> FFMIN((x << 1) >> scale, 31)) : 0;
674
2/2
✓ Branch 0 taken 5850576 times.
✓ Branch 1 taken 5300592 times.
22302336 wt = (mode == INTRA_HORZ) ? (32 >> FFMIN((y << 1) >> scale, 31)) : 0;
675 }
676 134878560 val = POS(x, y);
677 134878560 pred = val + ((wl * (l - val) + wt * (t - val) + 32) >> 6);
678 134878560 POS(x, y) = CLIP(pred);
679 }
680 }
681 }
682 }
683 1492280 }
684
685 //8.4.5.2.11 Specification of INTRA_PLANAR intra prediction mode
686 567182 static av_always_inline void FUNC(pred_planar)(uint8_t *_src, const uint8_t *_top,
687 const uint8_t *_left, const int w, const int h, const ptrdiff_t stride)
688 {
689 int x, y;
690 567182 pixel *src = (pixel *)_src;
691 567182 const pixel *top = (const pixel *)_top;
692 567182 const pixel *left = (const pixel *)_left;
693 567182 const int logw = av_log2(w);
694 567182 const int logh = av_log2(h);
695 567182 const int size = w * h;
696 567182 const int shift = (logw + logh + 1);
697
2/2
✓ Branch 0 taken 2910372 times.
✓ Branch 1 taken 283591 times.
6387926 for (y = 0; y < h; y++) {
698
2/2
✓ Branch 0 taken 49217488 times.
✓ Branch 1 taken 2910372 times.
104255720 for (x = 0; x < w; x++) {
699 98434976 const int pred_v = ((h - 1 - y) * top[x] + (y + 1) * left[h]) << logw;
700 98434976 const int pred_h = ((w - 1 - x) * left[y] + (x + 1) * top[w]) << logh;
701 98434976 const int pred = (pred_v + pred_h + size) >> shift;
702 98434976 POS(x, y) = pred;
703 }
704 }
705 567182 }
706
707 //8.4.5.2.3 MIP boundary sample downsampling process
708 300956 static av_always_inline void FUNC(mip_downsampling)(int *reduced, const int boundary_size,
709 const pixel *ref, const int n_tb_s)
710 {
711 300956 const int b_dwn = n_tb_s / boundary_size;
712 300956 const int log2 = av_log2(b_dwn);
713
714
2/2
✓ Branch 0 taken 26428 times.
✓ Branch 1 taken 124050 times.
300956 if (boundary_size == n_tb_s) {
715
2/2
✓ Branch 0 taken 105712 times.
✓ Branch 1 taken 26428 times.
264280 for (int i = 0; i < n_tb_s; i++)
716 211424 reduced[i] = ref[i];
717 52856 return;
718 }
719
2/2
✓ Branch 0 taken 464732 times.
✓ Branch 1 taken 124050 times.
1177564 for (int i = 0; i < boundary_size; i++) {
720 int r;
721 929464 r = *ref++;
722
2/2
✓ Branch 0 taken 1374156 times.
✓ Branch 1 taken 464732 times.
3677776 for (int j = 1; j < b_dwn; j++)
723 2748312 r += *ref++;
724 929464 reduced[i] = (r + (1 << (log2 - 1))) >> log2;
725 }
726 }
727
728 150478 static av_always_inline void FUNC(mip_reduced_pred)(pixel *src, const ptrdiff_t stride,
729 const int up_hor, const int up_ver, const int pred_size, const int *reduced, const int reduced_size,
730 const int ow, const int temp0, const uint8_t *matrix, int is_transposed)
731 {
732 150478 src = &POS(up_hor - 1, up_ver - 1);
733
2/2
✓ Branch 0 taken 434152 times.
✓ Branch 1 taken 75239 times.
1018782 for (int y = 0; y < pred_size; y++) {
734
2/2
✓ Branch 0 taken 2802176 times.
✓ Branch 1 taken 434152 times.
6472656 for (int x = 0; x < pred_size; x++) {
735 5604352 int pred = 0;
736
2/2
✓ Branch 0 taken 19782784 times.
✓ Branch 1 taken 2802176 times.
45169920 for (int i = 0; i < reduced_size; i++)
737 39565568 pred += reduced[i] * matrix[i];
738 5604352 matrix += reduced_size;
739 5604352 pred = ((pred + ow) >> 6) + temp0;
740 5604352 pred = av_clip(pred, 0, (1<<BIT_DEPTH) - 1);
741
2/2
✓ Branch 0 taken 1412304 times.
✓ Branch 1 taken 1389872 times.
5604352 if (is_transposed)
742 2824608 POS(y * up_hor, x * up_ver) = pred;
743 else
744 2779744 POS(x * up_hor, y * up_ver) = pred;
745 }
746 }
747 150478 }
748
749 181986 static av_always_inline void FUNC(mip_upsampling_1d)(pixel *dst, const int dst_step, const int dst_stride, const int dst_height, const int factor,
750 const pixel *boundary, const int boundary_step, const int pred_size)
751 {
752
753
2/2
✓ Branch 0 taken 898964 times.
✓ Branch 1 taken 90993 times.
1979914 for (int i = 0; i < dst_height; i++) {
754 1797928 const pixel *before = boundary;
755 1797928 const pixel *after = dst - dst_step;
756 1797928 pixel *d = dst;
757
2/2
✓ Branch 0 taken 6401904 times.
✓ Branch 1 taken 898964 times.
14601736 for (int j = 0; j < pred_size; j++) {
758 12803808 after += dst_step * factor;
759
2/2
✓ Branch 0 taken 13828752 times.
✓ Branch 1 taken 6401904 times.
40461312 for (int k = 1; k < factor; k++) {
760 27657504 int mid = (factor - k) * (*before) + k * (*after);
761 27657504 *d = (mid + factor / 2) / factor;
762 27657504 d += dst_step;
763 }
764 12803808 before = after;
765 12803808 d += dst_step;
766 }
767 1797928 boundary += boundary_step;
768 1797928 dst += dst_stride;
769 }
770 181986 }
771
772 //8.4.5.2.2 Matrix-based intra sample prediction
773 150478 static av_always_inline void FUNC(pred_mip)(uint8_t *_src, const uint8_t *_top,
774 const uint8_t *_left, const int w, const int h, const ptrdiff_t stride,
775 int mode_id, int is_transposed)
776 {
777 150478 pixel *src = (pixel *)_src;
778 150478 const pixel *top = (const pixel *)_top;
779 150478 const pixel *left = (const pixel *)_left;
780
781 150478 const int size_id = ff_vvc_get_mip_size_id(w, h);
782 static const int boundary_sizes[] = {2, 4, 4};
783 static const int pred_sizes[] = {4, 4, 8};
784 150478 const int boundary_size = boundary_sizes[size_id];
785 150478 const int pred_size = pred_sizes[size_id];
786 150478 const int in_size = 2 * boundary_size - ((size_id == 2) ? 1 : 0);
787 150478 const uint8_t *matrix = ff_vvc_get_mip_matrix(size_id, mode_id);
788 150478 const int up_hor = w / pred_size;
789 150478 const int up_ver = h / pred_size;
790
791 int reduced[16];
792 150478 int *red_t = reduced;
793 150478 int *red_l = reduced + boundary_size;
794 150478 int off = 1, ow = 0;
795 int temp0;
796
797
2/2
✓ Branch 0 taken 38484 times.
✓ Branch 1 taken 36755 times.
150478 if (is_transposed) {
798 76968 FFSWAP(int*, red_t, red_l);
799 }
800 150478 FUNC(mip_downsampling)(red_t, boundary_size, top, w);
801 150478 FUNC(mip_downsampling)(red_l, boundary_size, left, h);
802
803 150478 temp0 = reduced[0];
804
2/2
✓ Branch 0 taken 41940 times.
✓ Branch 1 taken 33299 times.
150478 if (size_id != 2) {
805 83880 off = 0;
806 83880 ow = (1 << (BIT_DEPTH - 1)) - temp0;
807 } else {
808 66598 ow = reduced[1] - temp0;
809 }
810 150478 reduced[0] = ow;
811
2/2
✓ Branch 0 taken 461906 times.
✓ Branch 1 taken 75239 times.
1074290 for (int i = 1; i < in_size; i++) {
812 923812 reduced[i] = reduced[i + off] - temp0;
813 923812 ow += reduced[i];
814 }
815 150478 ow = 32 - 32 * ow;
816
817 150478 FUNC(mip_reduced_pred)(src, stride, up_hor, up_ver, pred_size, reduced, in_size, ow, temp0, matrix, is_transposed);
818
4/4
✓ Branch 0 taken 24076 times.
✓ Branch 1 taken 51163 times.
✓ Branch 2 taken 16209 times.
✓ Branch 3 taken 7867 times.
150478 if (up_hor > 1 || up_ver > 1) {
819
2/2
✓ Branch 0 taken 51163 times.
✓ Branch 1 taken 16209 times.
134744 if (up_hor > 1)
820 102326 FUNC(mip_upsampling_1d)(&POS(0, up_ver - 1), 1, up_ver * stride, pred_size, up_hor, left + up_ver - 1, up_ver, pred_size);
821
2/2
✓ Branch 0 taken 39830 times.
✓ Branch 1 taken 27542 times.
134744 if (up_ver > 1)
822 79660 FUNC(mip_upsampling_1d)(src, stride, 1, w, up_ver, top, 1, pred_size);
823 }
824 150478 }
825
826 91474 static av_always_inline pixel FUNC(pred_dc_val)(const pixel *top, const pixel *left,
827 const int w, const int h)
828 {
829 pixel dc_val;
830 91474 int sum = 0;
831
2/2
✓ Branch 0 taken 14488 times.
✓ Branch 1 taken 31249 times.
91474 unsigned int offset = (w == h) ? (w << 1) : FFMAX(w, h);
832 91474 const int shift = av_log2(offset);
833 91474 offset >>= 1;
834
2/2
✓ Branch 0 taken 35063 times.
✓ Branch 1 taken 10674 times.
91474 if (w >= h) {
835
2/2
✓ Branch 0 taken 555464 times.
✓ Branch 1 taken 35063 times.
1181054 for (int i = 0; i < w; i++)
836 1110928 sum += top[i];
837 }
838
2/2
✓ Branch 0 taken 25162 times.
✓ Branch 1 taken 20575 times.
91474 if (w <= h) {
839
2/2
✓ Branch 0 taken 340704 times.
✓ Branch 1 taken 25162 times.
731732 for (int i = 0; i < h; i++)
840 681408 sum += left[i];
841 }
842 91474 dc_val = (sum + offset) >> shift;
843 91474 return dc_val;
844 }
845
846 //8.4.5.2.12 Specification of INTRA_DC intra prediction mode
847 91474 static av_always_inline void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top,
848 const uint8_t *_left, const int w, const int h, const ptrdiff_t stride)
849 {
850 int x, y;
851 91474 pixel *src = (pixel *)_src;
852 91474 const pixel *top = (const pixel *)_top;
853 91474 const pixel *left = (const pixel *)_left;
854 91474 const pixel dc = FUNC(pred_dc_val)(top, left, w, h);
855 91474 const pixel4 a = PIXEL_SPLAT_X4(dc);
856
2/2
✓ Branch 0 taken 461776 times.
✓ Branch 1 taken 45737 times.
1015026 for (y = 0; y < h; y++) {
857 923552 pixel *s = src;
858
2/2
✓ Branch 0 taken 2079408 times.
✓ Branch 1 taken 461776 times.
5082368 for (x = 0; x < w; x += 4) {
859 4158816 AV_WN4P(s, a);
860 4158816 s += 4;
861 }
862 923552 src += stride;
863 }
864 91474 }
865
866 72076 static av_always_inline void FUNC(pred_v)(uint8_t *_src, const uint8_t *_top,
867 const int w, const int h, const ptrdiff_t stride)
868 {
869 72076 pixel *src = (pixel *)_src;
870 72076 const pixel *top = (const pixel *)_top;
871
2/2
✓ Branch 0 taken 367964 times.
✓ Branch 1 taken 36038 times.
808004 for (int y = 0; y < h; y++) {
872 735928 memcpy(src, top, sizeof(pixel) * w);
873 735928 src += stride;
874 }
875 72076 }
876
877 68846 static void FUNC(pred_h)(uint8_t *_src, const uint8_t *_left, const int w, const int h,
878 const ptrdiff_t stride)
879 {
880 68846 pixel *src = (pixel *)_src;
881 68846 const pixel *left = (const pixel *)_left;
882
2/2
✓ Branch 0 taken 319820 times.
✓ Branch 1 taken 34423 times.
708486 for (int y = 0; y < h; y++) {
883 639640 const pixel4 a = PIXEL_SPLAT_X4(left[y]);
884
2/2
✓ Branch 0 taken 1579308 times.
✓ Branch 1 taken 319820 times.
3798256 for (int x = 0; x < w; x += 4) {
885 3158616 AV_WN4P(&POS(x, y), a);
886 }
887 }
888 68846 }
889
890 #define INTRA_LUMA_FILTER(p) CLIP((p[0] * f[0] + p[1] * f[1] + p[2] * f[2] + p[3] * f[3] + 32) >> 6)
891 #define INTRA_CHROMA_FILTER(p) (((32 - fact) * p[1] + fact * p[2] + 16) >> 5)
892
893 //8.4.5.2.13 Specification of INTRA_ANGULAR2..INTRA_ANGULAR66 intra prediction modes
894 279830 static void FUNC(pred_angular_v)(uint8_t *_src, const uint8_t *_top, const uint8_t *_left,
895 const int w, const int h, const ptrdiff_t stride, const int c_idx, const int mode,
896 const int ref_idx, const int filter_flag, const int need_pdpc)
897 {
898 279830 pixel *src = (pixel *)_src;
899 279830 const pixel *left = (const pixel *)_left;
900 279830 const pixel *top = (const pixel *)_top - (1 + ref_idx);
901 279830 const int intra_pred_angle = ff_vvc_intra_pred_angle_derive(mode);
902 279830 int pos = (1 + ref_idx) * intra_pred_angle;
903 279830 const int dp = intra_pred_angle;
904 279830 const int is_luma = !c_idx;
905 int nscale, inv_angle;
906
907
2/2
✓ Branch 0 taken 31151 times.
✓ Branch 1 taken 108764 times.
279830 if (need_pdpc) {
908 62302 inv_angle = ff_vvc_intra_inv_angle_derive(intra_pred_angle);
909 62302 nscale = ff_vvc_nscale_derive(w, h, mode);
910 }
911
912
2/2
✓ Branch 0 taken 1124048 times.
✓ Branch 1 taken 139915 times.
2527926 for (int y = 0; y < h; y++) {
913 2248096 const int idx = (pos >> 5) + ref_idx;
914 2248096 const int fact = pos & 31;
915
6/6
✓ Branch 0 taken 167024 times.
✓ Branch 1 taken 957024 times.
✓ Branch 2 taken 105644 times.
✓ Branch 3 taken 61380 times.
✓ Branch 4 taken 86715 times.
✓ Branch 5 taken 18929 times.
2248096 if (!fact && (!is_luma || !filter_flag)) {
916
2/2
✓ Branch 0 taken 1644640 times.
✓ Branch 1 taken 148095 times.
3585470 for (int x = 0; x < w; x++) {
917 3289280 const pixel *p = top + x + idx + 1;
918 3289280 POS(x, y) = *p;
919 }
920 } else {
921
2/2
✓ Branch 0 taken 752365 times.
✓ Branch 1 taken 223588 times.
1951906 if (!c_idx) {
922 1504730 const int8_t *f = ff_vvc_intra_luma_filter[filter_flag][fact];
923
2/2
✓ Branch 0 taken 8719392 times.
✓ Branch 1 taken 752365 times.
18943514 for (int x = 0; x < w; x++) {
924 17438784 const pixel *p = top + x + idx;
925 17438784 POS(x, y) = INTRA_LUMA_FILTER(p);
926 }
927 } else {
928
2/2
✓ Branch 0 taken 2115584 times.
✓ Branch 1 taken 223588 times.
4678344 for (int x = 0; x < w; x++) {
929 4231168 const pixel *p = top + x + idx;
930 4231168 POS(x, y) = INTRA_CHROMA_FILTER(p);
931 }
932 }
933 }
934
2/2
✓ Branch 0 taken 285064 times.
✓ Branch 1 taken 838984 times.
2248096 if (need_pdpc) {
935 570128 int inv_angle_sum = 256 + inv_angle;
936
2/2
✓ Branch 0 taken 1559476 times.
✓ Branch 1 taken 285064 times.
3689080 for (int x = 0; x < FFMIN(w, 3 << nscale); x++) {
937 3118952 const pixel l = left[y + (inv_angle_sum >> 9)];
938 3118952 const pixel val = POS(x, y);
939 3118952 const int wl = 32 >> ((x << 1) >> nscale);
940 3118952 const int pred = val + (((l - val) * wl + 32) >> 6);
941 3118952 POS(x, y) = CLIP(pred);
942 3118952 inv_angle_sum += inv_angle;
943 }
944 }
945 2248096 pos += dp;
946 }
947 279830 }
948
949 //8.4.5.2.13 Specification of INTRA_ANGULAR2..INTRA_ANGULAR66 intra prediction modes
950 262394 static void FUNC(pred_angular_h)(uint8_t *_src, const uint8_t *_top, const uint8_t *_left,
951 const int w, const int h, const ptrdiff_t stride, const int c_idx, const int mode,
952 const int ref_idx, const int filter_flag, const int need_pdpc)
953 {
954 262394 pixel *src = (pixel *)_src;
955 262394 const pixel *left = (const pixel *)_left - (1 + ref_idx);
956 262394 const pixel *top = (const pixel *)_top;
957 262394 const int is_luma = !c_idx;
958 262394 const int intra_pred_angle = ff_vvc_intra_pred_angle_derive(mode);
959 262394 const int dp = intra_pred_angle;
960 262394 int nscale = 0, inv_angle, inv_angle_sum;
961
962
2/2
✓ Branch 0 taken 26298 times.
✓ Branch 1 taken 104899 times.
262394 if (need_pdpc) {
963 52596 inv_angle = ff_vvc_intra_inv_angle_derive(intra_pred_angle);
964 52596 inv_angle_sum = 256 + inv_angle;
965 52596 nscale = ff_vvc_nscale_derive(w, h, mode);
966 }
967
968
2/2
✓ Branch 0 taken 1093660 times.
✓ Branch 1 taken 131197 times.
2449714 for (int y = 0; y < h; y++) {
969 2187320 int pos = (1 + ref_idx) * intra_pred_angle;
970 int wt;
971
2/2
✓ Branch 0 taken 302868 times.
✓ Branch 1 taken 790792 times.
2187320 if (need_pdpc)
972 605736 wt = (32 >> FFMIN(31, (y * 2) >> nscale));
973
974
2/2
✓ Branch 0 taken 16991104 times.
✓ Branch 1 taken 1093660 times.
36169528 for (int x = 0; x < w; x++) {
975 33982208 const int idx = (pos >> 5) + ref_idx;
976 33982208 const int fact = pos & 31;
977 33982208 const pixel *p = left + y + idx;
978 int pred;
979
6/6
✓ Branch 0 taken 1589976 times.
✓ Branch 1 taken 15401128 times.
✓ Branch 2 taken 1268028 times.
✓ Branch 3 taken 321948 times.
✓ Branch 4 taken 730492 times.
✓ Branch 5 taken 537536 times.
33982208 if (!fact && (!is_luma || !filter_flag)) {
980 2104880 pred = p[1];
981 } else {
982
2/2
✓ Branch 0 taken 12141060 times.
✓ Branch 1 taken 3797604 times.
31877328 if (!c_idx) {
983 24282120 const int8_t *f = ff_vvc_intra_luma_filter[filter_flag][fact];
984 24282120 pred = INTRA_LUMA_FILTER(p);
985 } else {
986 7595208 pred = INTRA_CHROMA_FILTER(p);
987 }
988 }
989
2/2
✓ Branch 0 taken 3798320 times.
✓ Branch 1 taken 13192784 times.
33982208 if (need_pdpc) {
990
2/2
✓ Branch 0 taken 1476028 times.
✓ Branch 1 taken 2322292 times.
7596640 if (y < (3 << nscale)) {
991 2952056 const pixel t = top[x + (inv_angle_sum >> 9)];
992 2952056 pred = CLIP(pred + (((t - pred) * wt + 32) >> 6));
993 }
994 }
995 33982208 POS(x, y) = pred;
996 33982208 pos += dp;
997 }
998
2/2
✓ Branch 0 taken 302868 times.
✓ Branch 1 taken 790792 times.
2187320 if (need_pdpc)
999 605736 inv_angle_sum += inv_angle;
1000 }
1001 262394 }
1002
1003 2326 static void FUNC(ff_vvc_intra_dsp_init)(VVCIntraDSPContext *const intra)
1004 {
1005 2326 intra->lmcs_scale_chroma = FUNC(lmcs_scale_chroma);
1006 2326 intra->intra_cclm_pred = FUNC(intra_cclm_pred);
1007 2326 intra->intra_pred = FUNC(intra_pred);
1008 2326 intra->pred_planar = FUNC(pred_planar);
1009 2326 intra->pred_mip = FUNC(pred_mip);
1010 2326 intra->pred_dc = FUNC(pred_dc);
1011 2326 intra->pred_v = FUNC(pred_v);
1012 2326 intra->pred_h = FUNC(pred_h);
1013 2326 intra->pred_angular_v = FUNC(pred_angular_v);
1014 2326 intra->pred_angular_h = FUNC(pred_angular_h);
1015 2326 }
1016