../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
620 / 626
99.0%
Branches:
307 / 324
94.8%
Functions:
36 / 36
100.0%

libavcodec/vvc/inter.c
Line Branch Exec Source
1 /*
2 * VVC inter prediction
3 *
4 * Copyright (C) 2022 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include "libavutil/frame.h"
23
24 #include "data.h"
25 #include "inter.h"
26 #include "mvs.h"
27 #include "refs.h"
28
29 // +1 is enough, + 32 for asm alignment
30 #define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32)
31 static const int bcw_w_lut[] = {4, 5, 3, 10, -2};
32
33 23780797 static void subpic_get_rect(VVCRect *r, const VVCFrame *src_frame, const int subpic_idx, const int is_chroma)
34 {
35 23780797 const VVCSPS *sps = src_frame->sps;
36 23780797 const VVCPPS *pps = src_frame->pps;
37 23780797 const int hs = sps->hshift[is_chroma];
38 23780797 const int vs = sps->vshift[is_chroma];
39
40 23780797 r->l = pps->subpic_x[subpic_idx] >> hs;
41 23780797 r->t = pps->subpic_y[subpic_idx] >> vs;
42 23780797 r->r = r->l + (pps->subpic_width[subpic_idx] >> hs);
43 23780797 r->b = r->t + (pps->subpic_height[subpic_idx] >> vs);
44 23780797 }
45
46 // clip to subblock and subpicture process in 8.5.6.3.2 Luma sample interpolation filtering process
47 23783038 static void clip_to_subpic(int *x_off, int *y_off, int *pic_width, int *pic_height, const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip)
48 {
49
4/4
✓ Branch 2 → 3 taken 1801622 times.
✓ Branch 2 → 6 taken 21981416 times.
✓ Branch 3 → 4 taken 128 times.
✓ Branch 3 → 5 taken 1801494 times.
23783038 const int l = dmvr_clip ? FFMIN(FFMAX(subpic->l, sb->l), subpic->r - 1) : subpic->l;
50
4/4
✓ Branch 7 → 8 taken 1801622 times.
✓ Branch 7 → 11 taken 21981416 times.
✓ Branch 8 → 9 taken 1066 times.
✓ Branch 8 → 10 taken 1800556 times.
23783038 const int t = dmvr_clip ? FFMIN(FFMAX(subpic->t, sb->t), subpic->b - 1) : subpic->t;
51
2/2
✓ Branch 12 → 13 taken 1801622 times.
✓ Branch 12 → 14 taken 21981416 times.
23783038 const int r = dmvr_clip ? FFMAX(FFMIN(subpic->r, sb->r), subpic->l + 1) : subpic->r;
52
2/2
✓ Branch 15 → 16 taken 1801622 times.
✓ Branch 15 → 17 taken 21981416 times.
23783038 const int b = dmvr_clip ? FFMAX(FFMIN(subpic->b, sb->b), subpic->t + 1) : subpic->b;
53
54 23783038 *x_off -= l;
55 23783038 *y_off -= t;
56 23783038 *pic_width = r - l;
57 23783038 *pic_height = b - t;
58 23783038 }
59
60 23778556 static void emulated_edge_no_wrap(const VVCLocalContext *lc, uint8_t *dst,
61 const uint8_t **src, ptrdiff_t *src_stride,
62 int x_off, int y_off, const int block_w, const int block_h,
63 const int extra_before, const int extra_after,
64 const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip)
65 {
66 23778556 const VVCFrameContext *fc = lc->fc;
67 23778556 const int extra = extra_before + extra_after;
68 int pic_width, pic_height;
69
70 23778556 *src += y_off * *src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
71
72 23778556 clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, sb, dmvr_clip);
73
74
6/6
✓ Branch 3 → 4 taken 21977044 times.
✓ Branch 3 → 8 taken 1801512 times.
✓ Branch 4 → 5 taken 21773302 times.
✓ Branch 4 → 8 taken 203742 times.
✓ Branch 5 → 6 taken 21440019 times.
✓ Branch 5 → 8 taken 333283 times.
23778556 if (dmvr_clip || x_off < extra_before || y_off < extra_before ||
75
2/2
✓ Branch 6 → 7 taken 21212658 times.
✓ Branch 6 → 8 taken 227361 times.
21440019 x_off >= pic_width - block_w - extra_after ||
76
2/2
✓ Branch 7 → 8 taken 296086 times.
✓ Branch 7 → 10 taken 20916572 times.
21212658 y_off >= pic_height - block_h - extra_after) {
77 2861984 const int ps = fc->ps.sps->pixel_shift;
78 2861984 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps;
79 2861984 const int offset = extra_before * *src_stride + (extra_before << ps);
80 2861984 const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps);
81
82 2861984 fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride,
83 block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before,
84 pic_width, pic_height);
85
86 2861984 *src = dst + buf_offset;
87 2861984 *src_stride = edge_emu_stride;
88 }
89 23778556 }
90
91 4482 static void emulated_half(const VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
92 const uint8_t *src, const ptrdiff_t src_stride, const int ps,
93 int x_off, int y_off, const int block_w, const int block_h,
94 const VVCRect *subpic,const VVCRect *half_sb, const int dmvr_clip)
95 {
96 4482 const VVCFrameContext *fc = lc->fc;
97 int pic_width, pic_height;
98
99 4482 src += y_off * src_stride + x_off * (1 << ps);
100
101 4482 clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, half_sb, dmvr_clip);
102
103 4482 fc->vdsp.emulated_edge_mc(dst, src, dst_stride, src_stride,
104 block_w, block_h, x_off, y_off, pic_width, pic_height);
105 4482 }
106
107 9897 static void sb_set_lr(VVCRect *sb, const int l, const int r)
108 {
109 9897 sb->l = l;
110 9897 sb->r = r;
111 9897 }
112
113 7656 static void sb_wrap(VVCRect *sb, const int wrap)
114 {
115 7656 sb_set_lr(sb, sb->l + wrap, sb->r + wrap);
116 7656 }
117
118 23780797 static void emulated_edge(const VVCLocalContext *lc, uint8_t *dst,
119 const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame,
120 int x_sb, int y_sb, int x_off, int y_off, int block_w, int block_h, const int wrap_enabled,
121 const int is_chroma, const int extra_before, const int extra_after)
122 {
123 23780797 const VVCSPS *sps = src_frame->sps;
124 23780797 const VVCPPS *pps = src_frame->pps;
125 23780797 const int ps = sps->pixel_shift;
126 23780797 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
127 23780797 const int extra = extra_before + extra_after;
128
4/4
✓ Branch 2 → 3 taken 22400530 times.
✓ Branch 2 → 4 taken 1380267 times.
✓ Branch 3 → 4 taken 421300 times.
✓ Branch 3 → 5 taken 21979230 times.
23780797 const int dmvr_clip = x_sb != x_off || y_sb != y_off;
129 23780797 const int dmvr_left = FFMAX(x_off, x_sb) - extra_before;
130 23780797 const int dmvr_right = FFMIN(x_off, x_sb) + block_w + extra_after;
131 23780797 const int left = x_off - extra_before;
132 23780797 const int top = y_off - extra_before;
133 23780797 const int pic_width = pps->width >> sps->hshift[is_chroma];
134 23780797 const int wrap = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]);
135 23780797 const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps;
136 23780797 VVCRect sb = { x_sb - extra_before, y_sb - extra_before, x_sb + block_w + extra_after, y_sb + block_h + extra_after };
137 VVCRect subpic;
138
139 23780797 subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma);
140
141
6/6
✓ Branch 7 → 8 taken 257536 times.
✓ Branch 7 → 10 taken 23523261 times.
✓ Branch 8 → 9 taken 251971 times.
✓ Branch 8 → 12 taken 5565 times.
✓ Branch 9 → 10 taken 247639 times.
✓ Branch 9 → 12 taken 4332 times.
23780797 if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) {
142 23770900 emulated_edge_no_wrap(lc, dst, src, src_stride,
143 x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
144 23778556 return;
145 }
146
2/2
✓ Branch 12 → 13 taken 4161 times.
✓ Branch 12 → 16 taken 5736 times.
9897 if (dmvr_right <= 0) {
147 4161 sb_wrap(&sb, wrap);
148 4161 emulated_edge_no_wrap(lc, dst, src, src_stride,
149 x_off + wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
150 4161 return;
151 }
152
2/2
✓ Branch 16 → 17 taken 3495 times.
✓ Branch 16 → 20 taken 2241 times.
5736 if (dmvr_left >= pic_width) {
153 3495 sb_wrap(&sb, -wrap);
154 3495 emulated_edge_no_wrap(lc, dst, src, src_stride,
155 x_off - wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
156 3495 return;
157 }
158
159 2241 block_w += extra;
160 2241 block_h += extra;
161
162 // half block are wrapped
163
2/2
✓ Branch 20 → 21 taken 1404 times.
✓ Branch 20 → 25 taken 837 times.
2241 if (dmvr_left < 0 ) {
164 1404 const int w = -left;
165 1404 VVCRect half_sb = { sb.l + wrap, sb.t, 0 + wrap, sb.b };
166 1404 emulated_half(lc, dst, dst_stride, *src, *src_stride, ps,
167 left + wrap, top, w, block_h, &subpic, &half_sb, dmvr_clip);
168
169 1404 sb_set_lr(&half_sb, 0, sb.r);
170 1404 emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps,
171 1404 0, top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip);
172 } else {
173 837 const int w = pic_width - left;
174 837 VVCRect half_sb = { sb.l, sb.t, pic_width, sb.b };
175 837 emulated_half(lc, dst, dst_stride, *src, *src_stride, ps,
176 left, top, w, block_h, &subpic, &half_sb, dmvr_clip);
177
178 837 sb_set_lr(&half_sb, pic_width - wrap, sb.r - wrap);
179 837 emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps,
180 837 pic_width - wrap , top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip);
181 }
182
183 2241 *src = dst + extra_before * dst_stride + (extra_before << ps);
184 2241 *src_stride = dst_stride;
185 }
186
187 #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off) \
188 emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \
189 is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER)
190
191 #define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \
192 emulated_edge(lc, dst, src, src_stride, ref, x_sb, y_sb, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \
193 is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER)
194
195 #define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \
196 emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, pred_w, pred_h, wrap_enabled, 0, \
197 BILINEAR_EXTRA_BEFORE, BILINEAR_EXTRA_AFTER)
198
199 // part of 8.5.6.6 Weighted sample prediction process
200 6472343 static int derive_weight_uni(int *denom, int *wx, int *ox,
201 const VVCLocalContext *lc, const MvField *mvf, const int c_idx)
202 {
203 6472343 const VVCFrameContext *fc = lc->fc;
204 6472343 const VVCPPS *pps = fc->ps.pps;
205 6472343 const VVCSH *sh = &lc->sc->sh;
206
4/4
✓ Branch 2 → 3 taken 1710162 times.
✓ Branch 2 → 4 taken 4762181 times.
✓ Branch 3 → 4 taken 1596084 times.
✓ Branch 3 → 6 taken 114078 times.
12830608 const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) ||
207
4/4
✓ Branch 4 → 5 taken 4762181 times.
✓ Branch 4 → 7 taken 1596084 times.
✓ Branch 5 → 6 taken 164004 times.
✓ Branch 5 → 7 taken 4598177 times.
6358265 (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag);
208
2/2
✓ Branch 8 → 9 taken 278082 times.
✓ Branch 8 → 13 taken 6194261 times.
6472343 if (weight_flag) {
209 278082 const int lx = mvf->pred_flag - PF_L0;
210
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 278082 times.
278082 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
211
212 278082 *denom = w->log2_denom[c_idx > 0];
213 278082 *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]];
214 278082 *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]];
215 }
216 6472343 return weight_flag;
217 }
218
219 // part of 8.5.6.6 Weighted sample prediction process
220 7102163 static void apply_averaging(uint8_t *dst, const ptrdiff_t dst_stride,
221 const int16_t *src0, const int16_t *src1, int width, int height,
222 const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag)
223 {
224 7102163 const VVCFrameContext *fc = lc->fc;
225 7102163 const VVCPPS *pps = fc->ps.pps;
226 7102163 const VVCSH *sh = &lc->sc->sh;
227 7102163 const int bcw_idx = mvf->bcw_idx;
228 av_assert2(IS_B(sh->r));
229
4/4
✓ Branch 2 → 3 taken 134267 times.
✓ Branch 2 → 5 taken 6967896 times.
✓ Branch 3 → 4 taken 134259 times.
✓ Branch 3 → 5 taken 8 times.
7102163 const int weight_flag = pps->r->pps_weighted_bipred_flag && !dmvr_flag;
230
8/8
✓ Branch 6 → 7 taken 6967904 times.
✓ Branch 6 → 8 taken 134259 times.
✓ Branch 7 → 8 taken 537580 times.
✓ Branch 7 → 10 taken 6430324 times.
✓ Branch 8 → 9 taken 538183 times.
✓ Branch 8 → 12 taken 133656 times.
✓ Branch 9 → 10 taken 3844 times.
✓ Branch 9 → 12 taken 534339 times.
7102163 if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag)) {
231 6434168 fc->vvcdsp.inter.avg(dst, dst_stride, src0, src1, width, height);
232 6434168 return;
233 }
234
235 int denom, w0, w1, o;
236
2/2
✓ Branch 12 → 13 taken 534339 times.
✓ Branch 12 → 14 taken 133656 times.
667995 if (bcw_idx) {
237 534339 denom = 2;
238 534339 w1 = bcw_w_lut[bcw_idx];
239 534339 w0 = 8 - w1;
240 534339 o = 0;
241 } else {
242
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 133656 times.
133656 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
243
244 133656 denom = w->log2_denom[c_idx > 0];
245 133656 w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]];
246 133656 w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]];
247 133656 o = w->offset[L0][c_idx][mvf->ref_idx[L0]]
248 133656 + w->offset[L1][c_idx][mvf->ref_idx[L1]];
249 }
250 667995 fc->vvcdsp.inter.w_avg(dst, dst_stride, src0, src1, width, height, denom, w0, w1, o);
251 }
252
253 #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac])
254
255 155741 static void mc(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv,
256 int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
257 {
258 155741 const VVCFrameContext *fc = lc->fc;
259 155741 const PredictionUnit *pu = &lc->cu->pu;
260 155741 const uint8_t *src = ref->frame->data[c_idx];
261 155741 ptrdiff_t src_stride = ref->frame->linesize[c_idx];
262 155741 const int is_chroma = !!c_idx;
263 155741 const int hs = fc->ps.sps->hshift[c_idx];
264 155741 const int vs = fc->ps.sps->vshift[c_idx];
265 155741 const int idx = av_log2(block_w) - 1;
266 155741 const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs);
267 155741 const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs);
268
4/4
✓ Branch 2 → 3 taken 54955 times.
✓ Branch 2 → 5 taken 100786 times.
✓ Branch 3 → 4 taken 40 times.
✓ Branch 3 → 5 taken 54915 times.
155741 const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx;
269
2/2
✓ Branch 6 → 7 taken 100786 times.
✓ Branch 6 → 8 taken 54955 times.
155741 const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
270
2/2
✓ Branch 9 → 10 taken 100786 times.
✓ Branch 9 → 11 taken 54955 times.
155741 const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
271 155741 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
272
273 155741 x_off += mv->x >> (4 + hs);
274 155741 y_off += mv->y >> (4 + vs);
275
276
4/4
✓ Branch 12 → 13 taken 100786 times.
✓ Branch 12 → 14 taken 54955 times.
✓ Branch 15 → 16 taken 100786 times.
✓ Branch 15 → 17 taken 54955 times.
155741 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, &src, &src_stride, x_off, y_off);
277 155741 fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
278 155741 }
279
280 3985364 static void mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
281 const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
282 const int c_idx)
283 {
284 3985364 const VVCFrameContext *fc = lc->fc;
285 3985364 const PredictionUnit *pu = &lc->cu->pu;
286 3985364 const uint8_t *src = ref->frame->data[c_idx];
287 3985364 ptrdiff_t src_stride = ref->frame->linesize[c_idx];
288 3985364 const int lx = mvf->pred_flag - PF_L0;
289 3985364 const int hs = fc->ps.sps->hshift[c_idx];
290 3985364 const int vs = fc->ps.sps->vshift[c_idx];
291 3985364 const int idx = av_log2(block_w) - 1;
292 3985364 const Mv *mv = &mvf->mv[lx];
293 3985364 const int is_chroma = !!c_idx;
294 3985364 const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs);
295 3985364 const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs);
296
2/2
✓ Branch 2 → 3 taken 788530 times.
✓ Branch 2 → 4 taken 3196834 times.
3985364 const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx;
297
2/2
✓ Branch 5 → 6 taken 3196834 times.
✓ Branch 5 → 7 taken 788530 times.
3985364 const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
298
2/2
✓ Branch 8 → 9 taken 3196834 times.
✓ Branch 8 → 10 taken 788530 times.
3985364 const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
299 3985364 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
300 int denom, wx, ox;
301
302 3985364 x_off += mv->x >> (4 + hs);
303 3985364 y_off += mv->y >> (4 + vs);
304
305
4/4
✓ Branch 11 → 12 taken 3196834 times.
✓ Branch 11 → 13 taken 788530 times.
✓ Branch 14 → 15 taken 3196834 times.
✓ Branch 14 → 16 taken 788530 times.
3985364 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, &src, &src_stride, x_off, y_off);
306
2/2
✓ Branch 19 → 20 taken 133496 times.
✓ Branch 19 → 21 taken 3851868 times.
3985364 if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) {
307 133496 fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
308 block_h, denom, wx, ox, hf, vf, block_w);
309 } else {
310 3851868 fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
311 block_h, hf, vf, block_w);
312 }
313 3985364 }
314
315 6405420 static void mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
316 const VVCFrame *ref0, const VVCFrame *ref1, const MvField *mvf, const MvField *orig_mv,
317 const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx,
318 const int sb_bdof_flag)
319 {
320 6405420 const VVCFrameContext *fc = lc->fc;
321 6405420 const PredictionUnit *pu = &lc->cu->pu;
322 6405420 const int hs = fc->ps.sps->hshift[c_idx];
323 6405420 const int vs = fc->ps.sps->vshift[c_idx];
324 6405420 const int idx = av_log2(block_w) - 1;
325 6405420 const VVCFrame *refs[] = { ref0, ref1 };
326 6405420 int16_t *tmp[] = { lc->pred.tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->pred.tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET };
327 6405420 const int is_chroma = !!c_idx;
328
2/2
✓ Branch 2 → 3 taken 1818126 times.
✓ Branch 2 → 4 taken 4587294 times.
6405420 const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx;
329
330
2/2
✓ Branch 31 → 6 taken 12810840 times.
✓ Branch 31 → 32 taken 6405420 times.
19216260 for (int i = L0; i <= L1; i++) {
331 12810840 const Mv *mv = mvf->mv + i;
332 12810840 const int mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs);
333 12810840 const int my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs);
334 12810840 const int ox = x_off + (mv->x >> (4 + hs));
335 12810840 const int oy = y_off + (mv->y >> (4 + vs));
336 12810840 const VVCFrame *ref = refs[i];
337 12810840 ptrdiff_t src_stride = ref->frame->linesize[c_idx];
338 12810840 const uint8_t *src = ref->frame->data[c_idx];
339
2/2
✓ Branch 6 → 7 taken 9174588 times.
✓ Branch 6 → 8 taken 3636252 times.
12810840 const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
340
2/2
✓ Branch 9 → 10 taken 9174588 times.
✓ Branch 9 → 11 taken 3636252 times.
12810840 const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
341 12810840 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
342
343
2/2
✓ Branch 12 → 13 taken 6664892 times.
✓ Branch 12 → 20 taken 6145948 times.
12810840 if (pu->dmvr_flag) {
344 6664892 const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs));
345 6664892 const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs));
346
347
4/4
✓ Branch 13 → 14 taken 4432304 times.
✓ Branch 13 → 15 taken 2232588 times.
✓ Branch 16 → 17 taken 4432304 times.
✓ Branch 16 → 18 taken 2232588 times.
6664892 MC_EMULATED_EDGE_DMVR(lc->pred.edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy);
348 } else {
349
4/4
✓ Branch 20 → 21 taken 4742284 times.
✓ Branch 20 → 22 taken 1403664 times.
✓ Branch 23 → 24 taken 4742284 times.
✓ Branch 23 → 25 taken 1403664 times.
6145948 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, &src, &src_stride, ox, oy);
350 }
351 12810840 fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w);
352
2/2
✓ Branch 28 → 29 taken 715100 times.
✓ Branch 28 → 30 taken 12095740 times.
12810840 if (sb_bdof_flag)
353 715100 fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h);
354 }
355
2/2
✓ Branch 32 → 33 taken 357550 times.
✓ Branch 32 → 34 taken 6047870 times.
6405420 if (sb_bdof_flag)
356 357550 fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
357 else
358 6047870 apply_averaging(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h,
359 6047870 lc, mvf, c_idx, pu->dmvr_flag);
360 6405420 }
361
362 65424 static const int8_t* inter_filter_scaled(const int scale, const int is_chroma, const int is_affine)
363 {
364 #define SCALE_THRESHOLD_1 20480
365 #define SCALE_THRESHOLD_2 28672
366
367 65424 const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1);
368
369
2/2
✓ Branch 2 → 3 taken 40888 times.
✓ Branch 2 → 6 taken 24536 times.
65424 if (!is_chroma) {
370
2/2
✓ Branch 3 → 4 taken 2728 times.
✓ Branch 3 → 5 taken 38160 times.
40888 if (!is_affine)
371 2728 return &ff_vvc_inter_luma_filters[i + !!i][0][0]; //hpel 1 is not needed for scaled
372 38160 return &ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE + i][0][0];
373 }
374
375 24536 return &ff_vvc_inter_chroma_filters[i][0][0];
376 }
377 #define INTER_FILTER_SCALED(scale) inter_filter_scaled(scale, is_chroma, is_affine)
378
379 #define SCALED_CHROMA_ADDIN(scale, collocated_flag) (is_chroma ? (collocated_flag ? 0 : 8 * (scale - (1 << 14))) : 0)
380 // Window offsets are in luma samples; block positions are in component samples.
381 #define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) (((((int64_t)(off) << (4 + shift)) - (scaling_off) * (1 << 4)) + ref_mv) * scale + add)
382 #define SCALED_REF(ref_sb, offset, shift) (FFSIGN(ref_sb) * ((FFABS(ref_sb) + (128 << shift)) >> (8 + shift)) + (offset * (1 << (10 - shift))) + (32 >> is_chroma))
383 #define SCALED_STEP(scale) ((scale + 8) >> 4)
384
385 32712 static void scaled_ref_pos_and_step(const VVCLocalContext *lc, const VVCRefPic *refp, const Mv *mv, const int x_off, const int y_off, const int c_idx,
386 int *x, int *y, int *dx, int *dy)
387 {
388 32712 const VVCFrameContext *fc = lc->fc;
389 32712 const VVCSPS *sps = fc->ps.sps;
390 32712 const int is_chroma = !!c_idx;
391 32712 const int hs = sps->hshift[c_idx];
392 32712 const int vs = sps->vshift[c_idx];
393 32712 const int left_offset = fc->ref->scaling_win.left_offset;
394 32712 const int top_offset = fc->ref->scaling_win.top_offset;
395
3/4
✓ Branch 2 → 3 taken 12268 times.
✓ Branch 2 → 6 taken 20444 times.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 12268 times.
32712 const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag);
396
3/4
✓ Branch 7 → 8 taken 12268 times.
✓ Branch 7 → 11 taken 20444 times.
✓ Branch 8 → 9 taken 12268 times.
✗ Branch 8 → 10 not taken.
32712 const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag);
397 32712 const int64_t refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs);
398 32712 const int64_t refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs);
399
400
2/2
✓ Branch 12 → 13 taken 32640 times.
✓ Branch 12 → 14 taken 72 times.
32712 *x = SCALED_REF(refx_sb, refp->ref->scaling_win.left_offset, hs);
401
2/2
✓ Branch 15 → 16 taken 32540 times.
✓ Branch 15 → 17 taken 172 times.
32712 *y = SCALED_REF(refy_sb, refp->ref->scaling_win.top_offset, vs);
402 32712 *dx = SCALED_STEP(refp->scale[0]);
403 32712 *dy = SCALED_STEP(refp->scale[1]);
404 32712 }
405
406 32712 static void emulated_edge_scaled(VVCLocalContext *lc, const uint8_t **src, ptrdiff_t *src_stride, int *src_height,
407 const VVCFrame *ref, const int x, const int y, const int dx, const int dy, const int w, const int h, const int is_chroma)
408 {
409 32712 const int x_off = SCALED_INT(x);
410 32712 const int y_off = SCALED_INT(y);
411 32712 const int x_end = SCALED_INT(x + w * dx);
412 32712 const int y_end = SCALED_INT(y + h * dy);
413 32712 const int x_last = SCALED_INT(x + (w - 1) * dx);
414 32712 const int y_last = SCALED_INT(y + (h - 1) * dy);
415 32712 const int block_w = x_end - x_off + (x_end == x_last);
416 32712 const int block_h = *src_height = y_end - y_off + (y_end == y_last);
417 32712 const int wrap_enabled = 0;
418
419
4/4
✓ Branch 2 → 3 taken 12268 times.
✓ Branch 2 → 4 taken 20444 times.
✓ Branch 5 → 6 taken 12268 times.
✓ Branch 5 → 7 taken 20444 times.
32712 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, src, src_stride, x_off, y_off);
420 32712 }
421
422 5949 static void mc_scaled(VVCLocalContext *lc, int16_t *dst, const VVCRefPic *refp, const Mv *mv,
423 int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
424 {
425 5949 const VVCFrameContext *fc = lc->fc;
426 5949 const PredictionUnit *pu = &lc->cu->pu;
427 5949 const uint8_t *src = refp->ref->frame->data[c_idx];
428 5949 ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx];
429 5949 const int is_affine = pu->inter_affine_flag;
430 5949 const int is_chroma = !!c_idx;
431 5949 const int idx = av_log2(block_w) - 1;
432 5949 const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]);
433 5949 const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]);
434 int x, y, dx, dy, src_height;
435
436 5949 scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy);
437 5949 emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma);
438 5949 fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w);
439 5949 }
440
441 26763 static void mc_uni_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp,
442 const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
443 {
444 26763 const VVCFrameContext *fc = lc->fc;
445 26763 const PredictionUnit *pu = &lc->cu->pu;
446 26763 const uint8_t *src = refp->ref->frame->data[c_idx];
447 26763 ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx];
448 26763 const int lx = mvf->pred_flag - PF_L0;
449 26763 const Mv *mv = &mvf->mv[lx];
450 26763 const int is_affine = pu->inter_affine_flag;
451 26763 const int is_chroma = !!c_idx;
452 26763 const int idx = av_log2(block_w) - 1;
453 26763 const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]);
454 26763 const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]);
455 int denom, wx, ox, x, y, dx, dy, src_height;
456
457 26763 scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy);
458 26763 emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma);
459
460
2/2
✓ Branch 7 → 8 taken 6 times.
✓ Branch 7 → 9 taken 26757 times.
26763 if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) {
461 6 fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height,
462 x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w);
463 } else {
464 26757 fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height,
465 x, y, dx, dy, block_h, hf, vf, block_w);
466 }
467 26763 }
468
469 1089 static void mc_bi_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
470 const VVCRefPic *refp0, const VVCRefPic *refp1, const MvField *mvf,
471 const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
472 {
473 1089 const VVCRefPic *refps[] = { refp0, refp1 };
474 1089 int16_t *tmp[] = { lc->pred.tmp, lc->pred.tmp1 };
475
476
2/2
✓ Branch 7 → 3 taken 2178 times.
✓ Branch 7 → 8 taken 1089 times.
3267 for (int i = L0; i <= L1; i++) {
477 2178 const Mv *mv = mvf->mv + i;
478 2178 const VVCRefPic *refp = refps[i];
479
480
2/2
✓ Branch 3 → 4 taken 2058 times.
✓ Branch 3 → 5 taken 120 times.
2178 if (refp->is_scaled)
481 2058 mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx);
482 else
483 120 mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx);
484 }
485 1089 apply_averaging(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h,
486 1089 lc, mvf, c_idx, lc->cu->pu.dmvr_flag);
487 1089 }
488
489 2460216 static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
490 const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
491 const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y)
492 {
493 2460216 const VVCFrameContext *fc = lc->fc;
494 2460216 const uint8_t *src = ref->frame->data[LUMA];
495 2460216 ptrdiff_t src_stride = ref->frame->linesize[LUMA];
496 2460216 uint16_t *prof_tmp = lc->pred.tmp + PROF_TEMP_OFFSET;
497 2460216 const int idx = av_log2(block_w) - 1;
498 2460216 const int lx = mvf->pred_flag - PF_L0;
499 2460216 const Mv *mv = mvf->mv + lx;
500 2460216 const int mx = mv->x & 0xf;
501 2460216 const int my = mv->y & 0xf;
502 2460216 const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx];
503 2460216 const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my];
504 int denom, wx, ox;
505 2460216 const int weight_flag = derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA);
506 2460216 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
507 2460216 const int is_chroma = 0;
508
509 2460216 x_off += mv->x >> 4;
510 2460216 y_off += mv->y >> 4;
511
512
2/4
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2460216 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 2460216 times.
2460216 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, &src, &src_stride, x_off, y_off);
513
2/2
✓ Branch 10 → 11 taken 2150840 times.
✓ Branch 10 → 16 taken 309376 times.
2460216 if (cb_prof_flag) {
514 2150840 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
515 2150840 fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
516
2/2
✓ Branch 13 → 14 taken 2136508 times.
✓ Branch 13 → 15 taken 14332 times.
2150840 if (!weight_flag)
517 2136508 fc->vvcdsp.inter.apply_prof_uni(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y);
518 else
519 14332 fc->vvcdsp.inter.apply_prof_uni_w(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y, denom, wx, ox);
520 } else {
521
2/2
✓ Branch 16 → 17 taken 179128 times.
✓ Branch 16 → 18 taken 130248 times.
309376 if (!weight_flag)
522 179128 fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w);
523 else
524 130248 fc->vvcdsp.inter.put_uni_w[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, denom, wx, ox, hf, vf, block_w);
525 }
526 2460216 }
527
528 2103336 static void luma_prof(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref,
529 const Mv *mv , const int x_off, const int y_off, const int block_w, const int block_h, const int lx)
530 {
531 2103336 const VVCFrameContext *fc = lc->fc;
532 2103336 const PredictionUnit *pu = &lc->cu->pu;
533 2103336 const int mx = mv->x & 0xf;
534 2103336 const int my = mv->y & 0xf;
535 2103336 const int ox = x_off + (mv->x >> 4);
536 2103336 const int oy = y_off + (mv->y >> 4);
537 2103336 const int idx = av_log2(block_w) - 1;
538 2103336 const int is_chroma = 0;
539 2103336 int16_t *prof_tmp = lc->pred.prof_tmp + PROF_TEMP_OFFSET;
540 2103336 ptrdiff_t src_stride = ref->frame->linesize[LUMA];
541 2103336 const uint8_t *src = ref->frame->data[LUMA];
542 2103336 const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx];
543 2103336 const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my];
544 2103336 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
545
546
2/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2103336 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 2103336 times.
2103336 MC_EMULATED_EDGE(lc->pred.edge_emu_buffer, &src, &src_stride, ox, oy);
547
2/2
✓ Branch 9 → 10 taken 692840 times.
✓ Branch 9 → 11 taken 1410496 times.
2103336 if (!pu->cb_prof_flag[lx]) {
548 692840 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
549 } else {
550 1410496 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
551 1410496 fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
552 1410496 fc->vvcdsp.inter.apply_prof(dst, prof_tmp, pu->diff_mv_x[lx], pu->diff_mv_y[lx]);
553 }
554 2103336 }
555
556 1053204 static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
557 const VVCRefPic *ref0, const VVCRefPic *ref1, const MvField *mvf, const int x_off, const int y_off,
558 const int block_w, const int block_h)
559 {
560 1053204 const VVCRefPic *refps[] = { ref0, ref1 };
561 1053204 int16_t *tmp[] = { lc->pred.tmp, lc->pred.tmp1 };
562
563
2/2
✓ Branch 7 → 3 taken 2106408 times.
✓ Branch 7 → 8 taken 1053204 times.
3159612 for (int i = L0; i <= L1; i++) {
564 2106408 const VVCRefPic *refp = refps[i];
565 2106408 const Mv *mv = mvf->mv + i;
566
567
2/2
✓ Branch 3 → 4 taken 3072 times.
✓ Branch 3 → 5 taken 2103336 times.
2106408 if (refp->is_scaled)
568 3072 mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, LUMA);
569 else
570 2103336 luma_prof(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, i);
571 }
572
573 1053204 apply_averaging(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, lc, mvf, LUMA, 0);
574 1053204 }
575
576 8571483 static int pred_get_refs(const VVCLocalContext *lc, VVCRefPic *refp[2], const MvField *mv)
577 {
578 8571483 RefPicList *rpl = lc->sc->rpl;
579
580
2/2
✓ Branch 7 → 3 taken 17142966 times.
✓ Branch 7 → 8 taken 8571483 times.
25714449 for (int mask = PF_L0; mask <= PF_L1; mask++) {
581
2/2
✓ Branch 3 → 4 taken 13049700 times.
✓ Branch 3 → 6 taken 4093266 times.
17142966 if (mv->pred_flag & mask) {
582 13049700 const int lx = mask - PF_L0;
583 13049700 refp[lx] = rpl[lx].refs + mv->ref_idx[lx];
584
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 13049700 times.
13049700 if (!refp[lx]->ref)
585 ✗ return AVERROR_INVALIDDATA;
586 }
587 }
588 8571483 return 0;
589 }
590
591 #define POS(c_idx, x, y) \
592 &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
593 (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
594
595 27594 static void pred_gpm_blk(VVCLocalContext *lc)
596 {
597 27594 const VVCFrameContext *fc = lc->fc;
598 27594 const CodingUnit *cu = lc->cu;
599 27594 const PredictionUnit *pu = &cu->pu;
600
601 27594 const uint8_t angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx];
602 27594 const uint8_t weights_idx = ff_vvc_gpm_angle_to_weights_idx[angle_idx];
603 27594 const int w = av_log2(cu->cb_width) - 3;
604 27594 const int h = av_log2(cu->cb_height) - 3;
605 27594 const uint8_t off_x = ff_vvc_gpm_weights_offset_x[pu->gpm_partition_idx][h][w];
606 27594 const uint8_t off_y = ff_vvc_gpm_weights_offset_y[pu->gpm_partition_idx][h][w];
607 27594 const uint8_t mirror_type = ff_vvc_gpm_angle_to_mirror[angle_idx];
608 const uint8_t *weights;
609
610
2/2
✓ Branch 2 → 3 taken 25313 times.
✓ Branch 2 → 4 taken 2281 times.
27594 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1;
611
612 27594 int16_t *tmp[2] = {lc->pred.tmp, lc->pred.tmp1};
613
614
2/2
✓ Branch 21 → 6 taken 78220 times.
✓ Branch 21 → 22 taken 27594 times.
105814 for (int c_idx = 0; c_idx < c_end; c_idx++) {
615 78220 const int hs = fc->ps.sps->hshift[c_idx];
616 78220 const int vs = fc->ps.sps->vshift[c_idx];
617 78220 const int x = lc->cu->x0 >> hs;
618 78220 const int y = lc->cu->y0 >> vs;
619 78220 const int width = cu->cb_width >> hs;
620 78220 const int height = cu->cb_height >> vs;
621 78220 uint8_t *dst = POS(c_idx, lc->cu->x0, lc->cu->y0);
622 78220 ptrdiff_t dst_stride = fc->frame->linesize[c_idx];
623
624 78220 int step_x = 1 << hs;
625 78220 int step_y = VVC_GPM_WEIGHT_SIZE << vs;
626
2/2
✓ Branch 6 → 7 taken 49435 times.
✓ Branch 6 → 8 taken 28785 times.
78220 if (!mirror_type) {
627 49435 weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + off_x];
628
2/2
✓ Branch 8 → 9 taken 12311 times.
✓ Branch 8 → 10 taken 16474 times.
28785 } else if (mirror_type == 1) {
629 12311 step_x = -step_x;
630 12311 weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + VVC_GPM_WEIGHT_SIZE - 1- off_x];
631 } else {
632 16474 step_y = -step_y;
633 16474 weights = &ff_vvc_gpm_weights[weights_idx][(VVC_GPM_WEIGHT_SIZE - 1 - off_y) * VVC_GPM_WEIGHT_SIZE + off_x];
634 }
635
636
2/2
✓ Branch 18 → 12 taken 156440 times.
✓ Branch 18 → 19 taken 78220 times.
234660 for (int i = 0; i < 2; i++) {
637 156440 const MvField *mv = pu->gpm_mv + i;
638 156440 const int lx = mv->pred_flag - PF_L0;
639 156440 VVCRefPic *refp = lc->sc->rpl[lx].refs + mv->ref_idx[lx];
640
641
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 156440 times.
156440 if (!refp->ref)
642 ✗ return;
643
2/2
✓ Branch 14 → 15 taken 819 times.
✓ Branch 14 → 16 taken 155621 times.
156440 if (refp->is_scaled)
644 819 mc_scaled(lc, tmp[i], refp, mv->mv + lx, x, y, width, height, c_idx);
645 else
646 155621 mc(lc, tmp[i], refp->ref, mv->mv + lx, x, y, width, height, c_idx);
647 }
648 78220 fc->vvcdsp.inter.put_gpm(dst, dst_stride, width, height, tmp[0], tmp[1], weights, step_x, step_y);
649 }
650 27594 return;
651 }
652
653 43833 static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0,
654 const int width, const int height)
655 {
656 43833 const VVCFrameContext *fc = lc->fc;
657 43833 const VVCSPS *sps = fc->ps.sps;
658 43833 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
659 43833 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
660
4/4
✓ Branch 2 → 3 taken 5187 times.
✓ Branch 2 → 4 taken 38646 times.
✓ Branch 3 → 4 taken 4249 times.
✓ Branch 3 → 5 taken 938 times.
43833 const int available_l = lc->ctb_left_flag || x0b;
661
4/4
✓ Branch 6 → 7 taken 6832 times.
✓ Branch 6 → 8 taken 37001 times.
✓ Branch 7 → 8 taken 6016 times.
✓ Branch 7 → 9 taken 816 times.
43833 const int available_u = lc->ctb_up_flag || y0b;
662 43833 const int min_pu_width = fc->ps.pps->min_pu_width;
663 43833 int w = 1;
664
665
4/4
✓ Branch 10 → 11 taken 43017 times.
✓ Branch 10 → 13 taken 816 times.
✓ Branch 11 → 12 taken 6198 times.
✓ Branch 11 → 13 taken 36819 times.
43833 if (available_u &&fc->tab.mvf[((y0 - 1) >> MIN_PU_LOG2) * min_pu_width + ((x0 - 1 + width)>> MIN_PU_LOG2)].pred_flag == PF_INTRA)
666 6198 w++;
667
668
4/4
✓ Branch 13 → 14 taken 42895 times.
✓ Branch 13 → 16 taken 938 times.
✓ Branch 14 → 15 taken 5922 times.
✓ Branch 14 → 16 taken 36973 times.
43833 if (available_l && fc->tab.mvf[((y0 - 1 + height)>> MIN_PU_LOG2) * min_pu_width + ((x0 - 1) >> MIN_PU_LOG2)].pred_flag == PF_INTRA)
669 5922 w++;
670
671 43833 return w;
672 }
673
674 3925761 static void pred_regular(VVCLocalContext *lc, const MvField *mvf, const MvField *orig_mvf,
675 const int x0, const int y0, const int sbw, const int sbh, const int sb_bdof_flag, const int c_start)
676 {
677 3925761 const VVCFrameContext *fc = lc->fc;
678
2/2
✓ Branch 2 → 3 taken 3897474 times.
✓ Branch 2 → 4 taken 28287 times.
3925761 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? CR : LUMA;
679 VVCRefPic *refp[2];
680
681
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3925761 times.
3925761 if (pred_get_refs(lc, refp, mvf) < 0)
682 ✗ return;
683
684
2/2
✓ Branch 40 → 9 taken 10402628 times.
✓ Branch 40 → 41 taken 3925761 times.
14328389 for (int c_idx = c_start; c_idx <= c_end; c_idx++) {
685 10402628 uint8_t *dst = POS(c_idx, x0, y0);
686 10402628 const ptrdiff_t dst_stride = fc->frame->linesize[c_idx];
687 10402628 const int hs = fc->ps.sps->hshift[c_idx];
688 10402628 const int vs = fc->ps.sps->vshift[c_idx];
689 10402628 const int x = x0 >> hs;
690 10402628 const int y = y0 >> vs;
691 10402628 const int w = sbw >> hs;
692 10402628 const int h = sbh >> vs;
693 10402628 const int is_luma = !c_idx;
694
6/6
✓ Branch 9 → 10 taken 48347 times.
✓ Branch 9 → 13 taken 10354281 times.
✓ Branch 10 → 11 taken 32020 times.
✓ Branch 10 → 12 taken 16327 times.
✓ Branch 11 → 12 taken 27506 times.
✓ Branch 11 → 13 taken 4514 times.
10402628 const int do_ciip = lc->cu->ciip_flag && (is_luma || (w > 2));
695
2/2
✓ Branch 14 → 15 taken 10358795 times.
✓ Branch 14 → 16 taken 43833 times.
10402628 uint8_t *inter = do_ciip ? lc->pred.ciip_tmp : dst;
696
2/2
✓ Branch 17 → 18 taken 10358795 times.
✓ Branch 17 → 19 taken 43833 times.
10402628 const ptrdiff_t inter_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst_stride;
697
4/4
✓ Branch 20 → 21 taken 2607680 times.
✓ Branch 20 → 23 taken 7794948 times.
✓ Branch 21 → 22 taken 357550 times.
✓ Branch 21 → 23 taken 2250130 times.
10402628 const int do_bdof = is_luma && sb_bdof_flag;
698
699
2/2
✓ Branch 24 → 25 taken 3996119 times.
✓ Branch 24 → 28 taken 6406509 times.
10402628 if (mvf->pred_flag != PF_BI) {
700 3996119 const int lx = mvf->pred_flag - PF_L0;
701
702
2/2
✓ Branch 25 → 26 taken 10755 times.
✓ Branch 25 → 27 taken 3985364 times.
3996119 if (refp[lx]->is_scaled) {
703 10755 mc_uni_scaled(lc, inter, inter_stride, refp[lx], mvf,
704 x, y, w, h, c_idx);
705 } else {
706 3985364 mc_uni(lc, inter, inter_stride, refp[lx]->ref, mvf,
707 x, y, w, h, c_idx);
708 }
709 } else {
710
4/4
✓ Branch 28 → 29 taken 6405429 times.
✓ Branch 28 → 30 taken 1080 times.
✓ Branch 29 → 30 taken 9 times.
✓ Branch 29 → 31 taken 6405420 times.
6406509 if (refp[L0]->is_scaled || refp[L1]->is_scaled) {
711 1089 mc_bi_scaled(lc, inter, inter_stride, refp[L0], refp[L1], mvf,
712 x, y, w, h, c_idx);
713 } else {
714 6405420 mc_bi(lc, inter, inter_stride, refp[L0]->ref, refp[L1]->ref, mvf, orig_mvf,
715 x, y, w, h, c_idx, do_bdof);
716 }
717 }
718
2/2
✓ Branch 32 → 33 taken 43833 times.
✓ Branch 32 → 39 taken 10358795 times.
10402628 if (do_ciip) {
719 43833 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
720 43833 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, c_idx);
721
4/4
✓ Branch 35 → 36 taken 16327 times.
✓ Branch 35 → 38 taken 27506 times.
✓ Branch 36 → 37 taken 8428 times.
✓ Branch 36 → 38 taken 7899 times.
43833 if (!c_idx && lc->sc->sh.r->sh_lmcs_used_flag)
722 8428 fc->vvcdsp.lmcs.filter(inter, inter_stride, w, h, &fc->ps.lmcs.fwd_lut);
723 43833 fc->vvcdsp.inter.put_ciip(dst, dst_stride, w, h, inter, inter_stride, intra_weight);
724 }
725 }
726 }
727
728 // 8.5.3.5 Parametric motion vector refinement process
729 514500 static int parametric_mv_refine(const int *sad, const int stride)
730 {
731 514500 const int sad_minus = sad[-stride];
732 514500 const int sad_center = sad[0];
733 514500 const int sad_plus = sad[stride];
734 int dmvc;
735 514500 int denom = (( sad_minus + sad_plus) - (sad_center << 1 ) ) << 3;
736
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 514500 times.
514500 if (!denom)
737 ✗ dmvc = 0;
738 else {
739
2/2
✓ Branch 4 → 5 taken 58 times.
✓ Branch 4 → 6 taken 514442 times.
514500 if (sad_minus == sad_center)
740 58 dmvc = -8;
741
2/2
✓ Branch 6 → 7 taken 244 times.
✓ Branch 6 → 8 taken 514198 times.
514442 else if (sad_plus == sad_center)
742 244 dmvc = 8;
743 else {
744 514198 int num = ( sad_minus - sad_plus ) * (1 << 4);
745 514198 int sign_num = 0;
746 514198 int quotient = 0;
747 514198 int counter = 3;
748
2/2
✓ Branch 8 → 9 taken 260163 times.
✓ Branch 8 → 10 taken 254035 times.
514198 if (num < 0 ) {
749 260163 num = - num;
750 260163 sign_num = 1;
751 }
752
2/2
✓ Branch 14 → 11 taken 1542594 times.
✓ Branch 14 → 15 taken 514198 times.
2056792 while (counter > 0) {
753 1542594 counter = counter - 1;
754 1542594 quotient = quotient << 1;
755
2/2
✓ Branch 11 → 12 taken 445866 times.
✓ Branch 11 → 13 taken 1096728 times.
1542594 if ( num >= denom ) {
756 445866 num = num - denom;
757 445866 quotient = quotient + 1;
758 }
759 1542594 denom = (denom >> 1);
760 }
761
2/2
✓ Branch 15 → 16 taken 260163 times.
✓ Branch 15 → 17 taken 254035 times.
514198 if (sign_num == 1 )
762 260163 dmvc = -quotient;
763 else
764 254035 dmvc = quotient;
765 }
766 }
767 514500 return dmvc;
768 }
769
770 #define SAD_ARRAY_SIZE 5
771 //8.5.3 Decoder-side motion vector refinement process
772 1116294 static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag,
773 const VVCFrame *ref0, const VVCFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h)
774 {
775 1116294 const VVCFrameContext *fc = lc->fc;
776 1116294 const int sr_range = 2;
777 1116294 const VVCFrame *refs[] = { ref0, ref1 };
778 1116294 int16_t *tmp[] = { lc->pred.tmp, lc->pred.tmp1 };
779 int sad[SAD_ARRAY_SIZE][SAD_ARRAY_SIZE];
780 int min_dx, min_dy, min_sad, dx, dy;
781
782 1116294 *orig_mv = *mvf;
783 1116294 min_dx = min_dy = dx = dy = 2;
784
785
2/2
✓ Branch 6 → 3 taken 2232588 times.
✓ Branch 6 → 7 taken 1116294 times.
3348882 for (int i = L0; i <= L1; i++) {
786 2232588 const int pred_w = block_w + 2 * sr_range;
787 2232588 const int pred_h = block_h + 2 * sr_range;
788 2232588 const Mv *mv = mvf->mv + i;
789 2232588 const int mx = mv->x & 0xf;
790 2232588 const int my = mv->y & 0xf;
791 2232588 const int ox = x_off + (mv->x >> 4) - sr_range;
792 2232588 const int oy = y_off + (mv->y >> 4) - sr_range;
793 2232588 const VVCFrame *ref = refs[i];
794 2232588 ptrdiff_t src_stride = ref->frame->linesize[LUMA];
795 2232588 const uint8_t *src = ref->frame->data[LUMA];
796 2232588 const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag;
797
798 2232588 MC_EMULATED_EDGE_BILINEAR(lc->pred.edge_emu_buffer, &src, &src_stride, ox, oy);
799 2232588 fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w);
800 }
801
802 1116294 min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h);
803 1116294 min_sad -= min_sad >> 2;
804 1116294 sad[dy][dx] = min_sad;
805
806
2/2
✓ Branch 8 → 9 taken 460533 times.
✓ Branch 8 → 32 taken 655761 times.
1116294 if (min_sad >= block_w * block_h) {
807 int dmv[2];
808 // 8.5.3.4 Array entry selection process
809
2/2
✓ Branch 19 → 10 taken 2302665 times.
✓ Branch 19 → 20 taken 460533 times.
2763198 for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
810
2/2
✓ Branch 17 → 11 taken 11513325 times.
✓ Branch 17 → 18 taken 2302665 times.
13815990 for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
811
4/4
✓ Branch 11 → 12 taken 2302665 times.
✓ Branch 11 → 13 taken 9210660 times.
✓ Branch 12 → 13 taken 1842132 times.
✓ Branch 12 → 16 taken 460533 times.
11513325 if (dx != sr_range || dy != sr_range) {
812 11052792 sad[dy][dx] = fc->vvcdsp.inter.sad(lc->pred.tmp, lc->pred.tmp1, dx, dy, block_w, block_h);
813
2/2
✓ Branch 14 → 15 taken 650256 times.
✓ Branch 14 → 16 taken 10402536 times.
11052792 if (sad[dy][dx] < min_sad) {
814 650256 min_sad = sad[dy][dx];
815 650256 min_dx = dx;
816 650256 min_dy = dy;
817 }
818 }
819 }
820 }
821 460533 dmv[0] = (min_dx - sr_range) * (1 << 4);
822 460533 dmv[1] = (min_dy - sr_range) * (1 << 4);
823
8/8
✓ Branch 20 → 21 taken 382857 times.
✓ Branch 20 → 27 taken 77676 times.
✓ Branch 21 → 22 taken 317984 times.
✓ Branch 21 → 27 taken 64873 times.
✓ Branch 22 → 23 taken 265754 times.
✓ Branch 22 → 27 taken 52230 times.
✓ Branch 23 → 24 taken 257250 times.
✓ Branch 23 → 27 taken 8504 times.
460533 if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) {
824 257250 dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1);
825 257250 dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE);
826 }
827
828
2/2
✓ Branch 30 → 28 taken 921066 times.
✓ Branch 30 → 31 taken 460533 times.
1381599 for (int i = L0; i <= L1; i++) {
829 921066 Mv *mv = mvf->mv + i;
830 921066 mv->x += (1 - 2 * i) * dmv[0];
831 921066 mv->y += (1 - 2 * i) * dmv[1];
832 921066 ff_vvc_clip_mv(mv);
833 }
834 }
835
2/2
✓ Branch 32 → 33 taken 825554 times.
✓ Branch 32 → 34 taken 290740 times.
1116294 if (min_sad < 2 * block_w * block_h) {
836 825554 *sb_bdof_flag = 0;
837 }
838 1116294 }
839
840 1116294 static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0,
841 const int width, const int height, const MvField *mvf)
842
843 {
844 1116294 const VVCPPS *pps = fc->ps.pps;
845
846
2/2
✓ Branch 7 → 3 taken 4420952 times.
✓ Branch 7 → 8 taken 1116294 times.
5537246 for (int y = y0; y < y0 + height; y += MIN_PU_SIZE) {
847
2/2
✓ Branch 5 → 4 taken 17546936 times.
✓ Branch 5 → 6 taken 4420952 times.
21967888 for (int x = x0; x < x0 + width; x += MIN_PU_SIZE) {
848 17546936 const int idx = pps->min_pu_width * (y >> MIN_PU_LOG2) + (x >> MIN_PU_LOG2);
849 17546936 fc->ref->tab_dmvr_mvf[idx] = *mvf;
850 }
851 }
852 1116294 }
853
854 2607680 static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag,
855 const int x0, const int y0, const int sbw, const int sbh)
856 {
857 2607680 VVCFrameContext *fc = lc->fc;
858 2607680 const PredictionUnit *pu = &lc->cu->pu;
859
860 2607680 *orig_mv = *mv = *ff_vvc_get_mvf(fc, x0, y0);
861
2/2
✓ Branch 3 → 4 taken 1183104 times.
✓ Branch 3 → 5 taken 1424576 times.
2607680 if (pu->bdof_flag)
862 1183104 *sb_bdof_flag = 1;
863
2/2
✓ Branch 5 → 6 taken 1116294 times.
✓ Branch 5 → 12 taken 1491386 times.
2607680 if (pu->dmvr_flag) {
864 VVCRefPic *refp[2];
865
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 1116294 times.
1116294 if (pred_get_refs(lc, refp, mv) < 0)
866 ✗ return;
867 1116294 dmvr_mv_refine(lc, mv, orig_mv, sb_bdof_flag, refp[L0]->ref, refp[L1]->ref, x0, y0, sbw, sbh);
868 1116294 set_dmvr_info(fc, x0, y0, sbw, sbh, mv);
869 }
870 }
871
872 415639 static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip)
873 {
874 415639 const CodingUnit *cu = lc->cu;
875 415639 PredictionUnit *pu = &lc->cu->pu;
876 415639 const MotionInfo *mi = &pu->mi;
877 MvField mv, orig_mv;
878 415639 int sbw, sbh, sb_bdof_flag = 0;
879
880
4/4
✓ Branch 2 → 3 taken 32654 times.
✓ Branch 2 → 5 taken 382985 times.
✓ Branch 3 → 4 taken 16327 times.
✓ Branch 3 → 5 taken 16327 times.
415639 if (cu->ciip_flag && skip_ciip)
881 16327 return;
882
883 399312 sbw = cu->cb_width / mi->num_sb_x;
884 399312 sbh = cu->cb_height / mi->num_sb_y;
885
886
2/2
✓ Branch 14 → 6 taken 662610 times.
✓ Branch 14 → 15 taken 399312 times.
1061922 for (int sby = 0; sby < mi->num_sb_y; sby++) {
887
2/2
✓ Branch 12 → 7 taken 2607680 times.
✓ Branch 12 → 13 taken 662610 times.
3270290 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
888 2607680 const int x0 = cu->x0 + sbx * sbw;
889 2607680 const int y0 = cu->y0 + sby * sbh;
890
891
2/2
✓ Branch 7 → 8 taken 16327 times.
✓ Branch 7 → 9 taken 2591353 times.
2607680 if (cu->ciip_flag)
892 16327 ff_vvc_set_neighbour_available(lc, x0, y0, sbw, sbh);
893
894 2607680 derive_sb_mv(lc, &mv, &orig_mv, &sb_bdof_flag, x0, y0, sbw, sbh);
895 2607680 pred_regular(lc, &mv, &orig_mv, x0, y0, sbw, sbh, sb_bdof_flag, LUMA);
896 }
897 }
898 }
899
900 1318081 static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv,
901 const int x0, const int y0, const int sbw, const int sbh)
902 {
903 1318081 const int hs = fc->ps.sps->hshift[1];
904 1318081 const int vs = fc->ps.sps->vshift[1];
905 1318081 const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh);
906 1318081 *mvc = *mv;
907
908 // Due to different pred_flag, one of the motion vectors may have an invalid value.
909 // Cast them to an unsigned type to avoid undefined behavior.
910 1318081 mvc->mv[0].x += (unsigned int)mv2->mv[0].x;
911 1318081 mvc->mv[0].y += (unsigned int)mv2->mv[0].y;
912 1318081 mvc->mv[1].x += (unsigned int)mv2->mv[1].x;
913 1318081 mvc->mv[1].y += (unsigned int)mv2->mv[1].y;
914 1318081 ff_vvc_round_mv(mvc->mv + 0, 0, 1);
915 1318081 ff_vvc_round_mv(mvc->mv + 1, 0, 1);
916 1318081 }
917
918 35980 static void pred_affine_blk(VVCLocalContext *lc)
919 {
920 35980 const VVCFrameContext *fc = lc->fc;
921 35980 const CodingUnit *cu = lc->cu;
922 35980 const PredictionUnit *pu = &cu->pu;
923 35980 const MotionInfo *mi = &pu->mi;
924 35980 const int x0 = cu->x0;
925 35980 const int y0 = cu->y0;
926 35980 const int sbw = cu->cb_width / mi->num_sb_x;
927 35980 const int sbh = cu->cb_height / mi->num_sb_y;
928 35980 const int hs = fc->ps.sps->hshift[1];
929 35980 const int vs = fc->ps.sps->vshift[1];
930 35980 const int dst_stride = fc->frame->linesize[LUMA];
931
932
2/2
✓ Branch 22 → 3 taken 284302 times.
✓ Branch 22 → 23 taken 35980 times.
320282 for (int sby = 0; sby < mi->num_sb_y; sby++) {
933
2/2
✓ Branch 20 → 4 taken 3529428 times.
✓ Branch 20 → 21 taken 284302 times.
3813730 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
934 3529428 const int x = x0 + sbx * sbw;
935 3529428 const int y = y0 + sby * sbh;
936
937 3529428 uint8_t *dst0 = POS(0, x, y);
938 3529428 const MvField *mv = ff_vvc_get_mvf(fc, x, y);
939 VVCRefPic *refp[2];
940
941
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3529428 times.
3529428 if (pred_get_refs(lc, refp, mv) < 0)
942 ✗ return;
943
944
2/2
✓ Branch 8 → 9 taken 2476224 times.
✓ Branch 8 → 12 taken 1053204 times.
3529428 if (mi->pred_flag != PF_BI) {
945 2476224 const int lx = mi->pred_flag - PF_L0;
946
2/2
✓ Branch 9 → 10 taken 16008 times.
✓ Branch 9 → 11 taken 2460216 times.
2476224 if (refp[lx]->is_scaled) {
947 16008 mc_uni_scaled(lc, dst0, dst_stride, refp[lx], mv, x, y, sbw, sbh, LUMA);
948 } else {
949 2460216 luma_prof_uni(lc, dst0, dst_stride, refp[lx]->ref,
950 mv, x, y, sbw, sbh, pu->cb_prof_flag[lx],
951 2460216 pu->diff_mv_x[lx], pu->diff_mv_y[lx]);
952 }
953 } else {
954 1053204 luma_prof_bi(lc, dst0, dst_stride, refp[L0], refp[L1], mv, x, y, sbw, sbh);
955 }
956
2/2
✓ Branch 13 → 14 taken 3491320 times.
✓ Branch 13 → 19 taken 38108 times.
3529428 if (fc->ps.sps->r->sps_chroma_format_idc) {
957
4/4
✓ Branch 14 → 15 taken 2043050 times.
✓ Branch 14 → 19 taken 1448270 times.
✓ Branch 15 → 16 taken 1318081 times.
✓ Branch 15 → 19 taken 724969 times.
3491320 if (!av_zero_extend(sby, vs) && !av_zero_extend(sbx, hs)) {
958 MvField mvc;
959
960 1318081 derive_affine_mvc(&mvc, fc, mv, x, y, sbw, sbh);
961 1318081 pred_regular(lc, &mvc, NULL, x, y, sbw << hs, sbh << vs, 0, CB);
962 }
963 }
964
965 }
966 }
967 }
968
969 462886 static void predict_inter(VVCLocalContext *lc)
970 {
971 462886 const VVCFrameContext *fc = lc->fc;
972 462886 const CodingUnit *cu = lc->cu;
973 462886 const PredictionUnit *pu = &cu->pu;
974
975
2/2
✓ Branch 2 → 3 taken 27594 times.
✓ Branch 2 → 4 taken 435292 times.
462886 if (pu->merge_gpm_flag)
976 27594 pred_gpm_blk(lc);
977
2/2
✓ Branch 4 → 5 taken 35980 times.
✓ Branch 4 → 6 taken 399312 times.
435292 else if (pu->inter_affine_flag)
978 35980 pred_affine_blk(lc);
979 else
980 399312 pred_regular_blk(lc, 1); //intra block is not ready yet, skip ciip
981
982
4/4
✓ Branch 7 → 8 taken 189745 times.
✓ Branch 7 → 10 taken 273141 times.
✓ Branch 8 → 9 taken 181317 times.
✓ Branch 8 → 10 taken 8428 times.
462886 if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
983 181317 uint8_t* dst0 = POS(0, cu->x0, cu->y0);
984 181317 fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
985 }
986 462886 }
987
988 1386939 static int has_inter_luma(const CodingUnit *cu)
989 {
990
4/6
✓ Branch 2 → 3 taken 924053 times.
✓ Branch 2 → 4 taken 462886 times.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 924053 times.
✓ Branch 4 → 5 taken 462886 times.
✗ Branch 4 → 6 not taken.
1386939 return (cu->pred_mode == MODE_INTER || cu->pred_mode == MODE_SKIP) && cu->tree_type != DUAL_TREE_CHROMA;
991 }
992
993 55838 int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs)
994 {
995 55838 const VVCFrameContext *fc = lc->fc;
996 55838 CodingUnit *cu = fc->tab.cus[rs];
997
998
2/2
✓ Branch 7 → 3 taken 1386939 times.
✓ Branch 7 → 8 taken 55838 times.
1442777 while (cu) {
999 1386939 lc->cu = cu;
1000
2/2
✓ Branch 4 → 5 taken 462886 times.
✓ Branch 4 → 6 taken 924053 times.
1386939 if (has_inter_luma(cu))
1001 462886 predict_inter(lc);
1002 1386939 cu = cu->next;
1003 }
1004
1005 55838 return 0;
1006 }
1007
1008 16327 void ff_vvc_predict_ciip(VVCLocalContext *lc)
1009 {
1010
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 16327 times.
16327 av_assert0(lc->cu->ciip_flag);
1011
1012 //todo: refact out ciip from pred_regular_blk
1013 16327 pred_regular_blk(lc, 0);
1014 16327 }
1015
1016 #undef POS
1017