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 | 20479225 | static void subpic_get_rect(VVCRect *r, const VVCFrame *src_frame, const int subpic_idx, const int is_chroma) | |
34 | { | ||
35 | 20479225 | const VVCSPS *sps = src_frame->sps; | |
36 | 20479225 | const VVCPPS *pps = src_frame->pps; | |
37 | 20479225 | const int hs = sps->hshift[is_chroma]; | |
38 | 20479225 | const int vs = sps->vshift[is_chroma]; | |
39 | |||
40 | 20479225 | r->l = pps->subpic_x[subpic_idx] >> hs; | |
41 | 20479225 | r->t = pps->subpic_y[subpic_idx] >> vs; | |
42 | 20479225 | r->r = r->l + (pps->subpic_width[subpic_idx] >> hs); | |
43 | 20479225 | r->b = r->t + (pps->subpic_height[subpic_idx] >> vs); | |
44 | 20479225 | } | |
45 | |||
46 | // clip to subblock and subpicture process in 8.5.6.3.2 Luma sample interpolation filtering process | ||
47 | 20481466 | 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 0 taken 1776902 times.
✓ Branch 1 taken 18704564 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 1776774 times.
|
20481466 | const int l = dmvr_clip ? FFMIN(FFMAX(subpic->l, sb->l), subpic->r - 1) : subpic->l; |
50 |
4/4✓ Branch 0 taken 1776902 times.
✓ Branch 1 taken 18704564 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 1775836 times.
|
20481466 | const int t = dmvr_clip ? FFMIN(FFMAX(subpic->t, sb->t), subpic->b - 1) : subpic->t; |
51 |
2/2✓ Branch 0 taken 1776902 times.
✓ Branch 1 taken 18704564 times.
|
20481466 | const int r = dmvr_clip ? FFMAX(FFMIN(subpic->r, sb->r), subpic->l + 1) : subpic->r; |
52 |
2/2✓ Branch 0 taken 1776902 times.
✓ Branch 1 taken 18704564 times.
|
20481466 | const int b = dmvr_clip ? FFMAX(FFMIN(subpic->b, sb->b), subpic->t + 1) : subpic->b; |
53 | |||
54 | 20481466 | *x_off -= l; | |
55 | 20481466 | *y_off -= t; | |
56 | 20481466 | *pic_width = r - l; | |
57 | 20481466 | *pic_height = b - t; | |
58 | 20481466 | } | |
59 | |||
60 | 20476984 | 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 | 20476984 | const VVCFrameContext *fc = lc->fc; | |
67 | 20476984 | const int extra = extra_before + extra_after; | |
68 | int pic_width, pic_height; | ||
69 | |||
70 | 20476984 | *src += y_off * *src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); | |
71 | |||
72 | 20476984 | clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, sb, dmvr_clip); | |
73 | |||
74 |
6/6✓ Branch 0 taken 18700192 times.
✓ Branch 1 taken 1776792 times.
✓ Branch 2 taken 18528099 times.
✓ Branch 3 taken 172093 times.
✓ Branch 4 taken 18245088 times.
✓ Branch 5 taken 283011 times.
|
20476984 | if (dmvr_clip || x_off < extra_before || y_off < extra_before || |
75 |
2/2✓ Branch 0 taken 18042067 times.
✓ Branch 1 taken 203021 times.
|
18245088 | x_off >= pic_width - block_w - extra_after || |
76 |
2/2✓ Branch 0 taken 251951 times.
✓ Branch 1 taken 17790116 times.
|
18042067 | y_off >= pic_height - block_h - extra_after) { |
77 | 2686868 | const int ps = fc->ps.sps->pixel_shift; | |
78 | 2686868 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
79 | 2686868 | const int offset = extra_before * *src_stride + (extra_before << ps); | |
80 | 2686868 | const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps); | |
81 | |||
82 | 2686868 | 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 | 2686868 | *src = dst + buf_offset; | |
87 | 2686868 | *src_stride = edge_emu_stride; | |
88 | } | ||
89 | 20476984 | } | |
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 | 20479225 | 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 | 20479225 | const VVCSPS *sps = src_frame->sps; | |
124 | 20479225 | const VVCPPS *pps = src_frame->pps; | |
125 | 20479225 | const int ps = sps->pixel_shift; | |
126 | 20479225 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
127 | 20479225 | const int extra = extra_before + extra_after; | |
128 |
4/4✓ Branch 0 taken 19116950 times.
✓ Branch 1 taken 1362275 times.
✓ Branch 2 taken 414572 times.
✓ Branch 3 taken 18702378 times.
|
20479225 | const int dmvr_clip = x_sb != x_off || y_sb != y_off; |
129 | 20479225 | const int dmvr_left = FFMAX(x_off, x_sb) - extra_before; | |
130 | 20479225 | const int dmvr_right = FFMIN(x_off, x_sb) + block_w + extra_after; | |
131 | 20479225 | const int left = x_off - extra_before; | |
132 | 20479225 | const int top = y_off - extra_before; | |
133 | 20479225 | const int pic_width = pps->width >> sps->hshift[is_chroma]; | |
134 | 20479225 | const int wrap = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]); | |
135 | 20479225 | const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
136 | 20479225 | 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 | 20479225 | subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma); | |
140 | |||
141 |
6/6✓ Branch 0 taken 257536 times.
✓ Branch 1 taken 20221689 times.
✓ Branch 2 taken 251971 times.
✓ Branch 3 taken 5565 times.
✓ Branch 4 taken 247639 times.
✓ Branch 5 taken 4332 times.
|
20479225 | if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) { |
142 | 20469328 | 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 | 20476984 | return; | |
145 | } | ||
146 |
2/2✓ Branch 0 taken 4161 times.
✓ Branch 1 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 0 taken 3495 times.
✓ Branch 1 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 0 taken 1404 times.
✓ Branch 1 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 | 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 | 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 | 5897353 | static int derive_weight_uni(int *denom, int *wx, int *ox, | |
201 | const VVCLocalContext *lc, const MvField *mvf, const int c_idx) | ||
202 | { | ||
203 | 5897353 | const VVCFrameContext *fc = lc->fc; | |
204 | 5897353 | const VVCPPS *pps = fc->ps.pps; | |
205 | 5897353 | const VVCSH *sh = &lc->sc->sh; | |
206 |
4/4✓ Branch 0 taken 1707465 times.
✓ Branch 1 taken 4189888 times.
✓ Branch 2 taken 1593390 times.
✓ Branch 3 taken 114075 times.
|
11680631 | const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || |
207 |
4/4✓ Branch 0 taken 4189888 times.
✓ Branch 1 taken 1593390 times.
✓ Branch 2 taken 163995 times.
✓ Branch 3 taken 4025893 times.
|
5783278 | (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag); |
208 |
2/2✓ Branch 0 taken 278070 times.
✓ Branch 1 taken 5619283 times.
|
5897353 | if (weight_flag) { |
209 | 278070 | const int lx = mvf->pred_flag - PF_L0; | |
210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 278070 times.
|
278070 | const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; |
211 | |||
212 | 278070 | *denom = w->log2_denom[c_idx > 0]; | |
213 | 278070 | *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]]; | |
214 | 278070 | *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]]; | |
215 | } | ||
216 | 5897353 | return weight_flag; | |
217 | } | ||
218 | |||
219 | // part of 8.5.6.6 Weighted sample prediction process | ||
220 | 6235195 | static int derive_weight(int *denom, int *w0, int *w1, int *o0, int *o1, | |
221 | const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag) | ||
222 | { | ||
223 | 6235195 | const VVCFrameContext *fc = lc->fc; | |
224 | 6235195 | const VVCPPS *pps = fc->ps.pps; | |
225 | 6235195 | const VVCSH *sh = &lc->sc->sh; | |
226 | 6235195 | const int bcw_idx = mvf->bcw_idx; | |
227 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6235195 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
12470390 | const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || |
228 |
5/6✓ Branch 0 taken 6235195 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134292 times.
✓ Branch 3 taken 6100903 times.
✓ Branch 4 taken 134280 times.
✓ Branch 5 taken 12 times.
|
6235195 | (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag); |
229 |
8/8✓ Branch 0 taken 6100915 times.
✓ Branch 1 taken 134280 times.
✓ Branch 2 taken 500326 times.
✓ Branch 3 taken 5600589 times.
✓ Branch 4 taken 500929 times.
✓ Branch 5 taken 133677 times.
✓ Branch 6 taken 3709 times.
✓ Branch 7 taken 497220 times.
|
6235195 | if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag)) |
230 | 5604298 | return 0; | |
231 | |||
232 |
2/2✓ Branch 0 taken 497220 times.
✓ Branch 1 taken 133677 times.
|
630897 | if (bcw_idx) { |
233 | 497220 | *denom = 2; | |
234 | 497220 | *w1 = bcw_w_lut[bcw_idx]; | |
235 | 497220 | *w0 = 8 - *w1; | |
236 | 497220 | *o0 = *o1 = 0; | |
237 | } else { | ||
238 | 133677 | const VVCPPS *pps = fc->ps.pps; | |
239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 133677 times.
|
133677 | const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; |
240 | |||
241 | 133677 | *denom = w->log2_denom[c_idx > 0]; | |
242 | 133677 | *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]]; | |
243 | 133677 | *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]]; | |
244 | 133677 | *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]]; | |
245 | 133677 | *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]]; | |
246 | } | ||
247 | 630897 | return 1; | |
248 | } | ||
249 | |||
250 | #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac]) | ||
251 | |||
252 | 143864 | static void mc(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv, | |
253 | int x_off, int y_off, const int block_w, const int block_h, const int c_idx) | ||
254 | { | ||
255 | 143864 | const VVCFrameContext *fc = lc->fc; | |
256 | 143864 | const PredictionUnit *pu = &lc->cu->pu; | |
257 | 143864 | const uint8_t *src = ref->frame->data[c_idx]; | |
258 | 143864 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
259 | 143864 | const int is_chroma = !!c_idx; | |
260 | 143864 | const int hs = fc->ps.sps->hshift[c_idx]; | |
261 | 143864 | const int vs = fc->ps.sps->vshift[c_idx]; | |
262 | 143864 | const int idx = av_log2(block_w) - 1; | |
263 | 143864 | const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
264 | 143864 | const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
265 |
4/4✓ Branch 0 taken 50996 times.
✓ Branch 1 taken 92868 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 50957 times.
|
143864 | const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx; |
266 |
2/2✓ Branch 0 taken 92868 times.
✓ Branch 1 taken 50996 times.
|
143864 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
267 |
2/2✓ Branch 0 taken 92868 times.
✓ Branch 1 taken 50996 times.
|
143864 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
268 | 143864 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
269 | |||
270 | 143864 | x_off += mv->x >> (4 + hs); | |
271 | 143864 | y_off += mv->y >> (4 + vs); | |
272 | |||
273 |
4/4✓ Branch 0 taken 92868 times.
✓ Branch 1 taken 50996 times.
✓ Branch 2 taken 92868 times.
✓ Branch 3 taken 50996 times.
|
143864 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
274 | 143864 | fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); | |
275 | 143864 | } | |
276 | |||
277 | 3448188 | static void mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
278 | const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, | ||
279 | const int c_idx) | ||
280 | { | ||
281 | 3448188 | const VVCFrameContext *fc = lc->fc; | |
282 | 3448188 | const PredictionUnit *pu = &lc->cu->pu; | |
283 | 3448188 | const uint8_t *src = ref->frame->data[c_idx]; | |
284 | 3448188 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
285 | 3448188 | const int lx = mvf->pred_flag - PF_L0; | |
286 | 3448188 | const int hs = fc->ps.sps->hshift[c_idx]; | |
287 | 3448188 | const int vs = fc->ps.sps->vshift[c_idx]; | |
288 | 3448188 | const int idx = av_log2(block_w) - 1; | |
289 | 3448188 | const Mv *mv = &mvf->mv[lx]; | |
290 | 3448188 | const int is_chroma = !!c_idx; | |
291 | 3448188 | const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
292 | 3448188 | const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
293 |
2/2✓ Branch 0 taken 629160 times.
✓ Branch 1 taken 2819028 times.
|
3448188 | const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; |
294 |
2/2✓ Branch 0 taken 2819028 times.
✓ Branch 1 taken 629160 times.
|
3448188 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
295 |
2/2✓ Branch 0 taken 2819028 times.
✓ Branch 1 taken 629160 times.
|
3448188 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
296 | 3448188 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
297 | int denom, wx, ox; | ||
298 | |||
299 | 3448188 | x_off += mv->x >> (4 + hs); | |
300 | 3448188 | y_off += mv->y >> (4 + vs); | |
301 | |||
302 |
4/4✓ Branch 0 taken 2819028 times.
✓ Branch 1 taken 629160 times.
✓ Branch 2 taken 2819028 times.
✓ Branch 3 taken 629160 times.
|
3448188 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
303 |
2/2✓ Branch 1 taken 133490 times.
✓ Branch 2 taken 3314698 times.
|
3448188 | if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { |
304 | 133490 | fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, | |
305 | block_h, denom, wx, ox, hf, vf, block_w); | ||
306 | } else { | ||
307 | 3314698 | fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, | |
308 | block_h, hf, vf, block_w); | ||
309 | } | ||
310 | 3448188 | } | |
311 | |||
312 | 5294453 | static void mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
313 | const VVCFrame *ref0, const VVCFrame *ref1, const MvField *mvf, const MvField *orig_mv, | ||
314 | const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx, | ||
315 | const int sb_bdof_flag) | ||
316 | { | ||
317 | 5294453 | const VVCFrameContext *fc = lc->fc; | |
318 | 5294453 | const PredictionUnit *pu = &lc->cu->pu; | |
319 | 5294453 | const int hs = fc->ps.sps->hshift[c_idx]; | |
320 | 5294453 | const int vs = fc->ps.sps->vshift[c_idx]; | |
321 | 5294453 | const int idx = av_log2(block_w) - 1; | |
322 | 5294453 | const VVCFrame *refs[] = { ref0, ref1 }; | |
323 | 5294453 | int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET }; | |
324 | int denom, w0, w1, o0, o1; | ||
325 | 5294453 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, pu->dmvr_flag); | |
326 | 5294453 | const int is_chroma = !!c_idx; | |
327 |
2/2✓ Branch 0 taken 1513965 times.
✓ Branch 1 taken 3780488 times.
|
5294453 | const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; |
328 | |||
329 |
2/2✓ Branch 0 taken 10588906 times.
✓ Branch 1 taken 5294453 times.
|
15883359 | for (int i = L0; i <= L1; i++) { |
330 | 10588906 | const Mv *mv = mvf->mv + i; | |
331 | 10588906 | const int mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
332 | 10588906 | const int my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
333 | 10588906 | const int ox = x_off + (mv->x >> (4 + hs)); | |
334 | 10588906 | const int oy = y_off + (mv->y >> (4 + vs)); | |
335 | 10588906 | const VVCFrame *ref = refs[i]; | |
336 | 10588906 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
337 | 10588906 | const uint8_t *src = ref->frame->data[c_idx]; | |
338 |
2/2✓ Branch 0 taken 7560976 times.
✓ Branch 1 taken 3027930 times.
|
10588906 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
339 |
2/2✓ Branch 0 taken 7560976 times.
✓ Branch 1 taken 3027930 times.
|
10588906 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
340 | 10588906 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
341 | |||
342 |
2/2✓ Branch 0 taken 5867876 times.
✓ Branch 1 taken 4721030 times.
|
10588906 | if (pu->dmvr_flag) { |
343 | 5867876 | const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs)); | |
344 | 5867876 | const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs)); | |
345 | |||
346 |
4/4✓ Branch 0 taken 3900960 times.
✓ Branch 1 taken 1966916 times.
✓ Branch 2 taken 3900960 times.
✓ Branch 3 taken 1966916 times.
|
5867876 | MC_EMULATED_EDGE_DMVR(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy); |
347 | } else { | ||
348 |
4/4✓ Branch 0 taken 3660016 times.
✓ Branch 1 taken 1061014 times.
✓ Branch 2 taken 3660016 times.
✓ Branch 3 taken 1061014 times.
|
4721030 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); |
349 | } | ||
350 | 10588906 | fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w); | |
351 |
2/2✓ Branch 0 taken 696506 times.
✓ Branch 1 taken 9892400 times.
|
10588906 | if (sb_bdof_flag) |
352 | 696506 | fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h); | |
353 | } | ||
354 |
2/2✓ Branch 0 taken 348253 times.
✓ Branch 1 taken 4946200 times.
|
5294453 | if (sb_bdof_flag) |
355 | 348253 | fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
356 |
2/2✓ Branch 0 taken 355873 times.
✓ Branch 1 taken 4590327 times.
|
4946200 | else if (weight_flag) |
357 | 355873 | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
358 | else | ||
359 | 4590327 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
360 | 5294453 | } | |
361 | |||
362 | 65406 | 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 | 65406 | const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1); | |
368 | |||
369 |
2/2✓ Branch 0 taken 40882 times.
✓ Branch 1 taken 24524 times.
|
65406 | if (!is_chroma) { |
370 |
2/2✓ Branch 0 taken 2722 times.
✓ Branch 1 taken 38160 times.
|
40882 | if (!is_affine) |
371 | 2722 | 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 | 24524 | 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 | #define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) ((((off - (scaling_off << shift)) << (4 + shift)) + ref_mv) * scale + add) | ||
381 | #define SCALED_REF(ref_sb, offset, shift) (FFSIGN(ref_sb) * ((FFABS(ref_sb) + (128 << is_chroma)) >> (8 + is_chroma)) + (offset << (10 - shift)) + (32 >> is_chroma)) | ||
382 | #define SCALED_STEP(scale) ((scale + 8) >> 4) | ||
383 | |||
384 | 32703 | 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, | |
385 | int *x, int *y, int *dx, int *dy) | ||
386 | { | ||
387 | 32703 | const VVCFrameContext *fc = lc->fc; | |
388 | 32703 | const VVCSPS *sps = fc->ps.sps; | |
389 | 32703 | const int is_chroma = !!c_idx; | |
390 | 32703 | const int hs = sps->hshift[c_idx]; | |
391 | 32703 | const int vs = sps->vshift[c_idx]; | |
392 | 32703 | const int left_offset = fc->ref->scaling_win.left_offset; | |
393 | 32703 | const int top_offset = fc->ref->scaling_win.top_offset; | |
394 |
3/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12262 times.
|
32703 | const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag); |
395 |
3/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✓ Branch 2 taken 12262 times.
✗ Branch 3 not taken.
|
32703 | const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag); |
396 | 32703 | const int refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs); | |
397 | 32703 | const int refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs); | |
398 | |||
399 |
2/2✓ Branch 0 taken 32637 times.
✓ Branch 1 taken 66 times.
|
32703 | *x = SCALED_REF(refx_sb, left_offset, hs); |
400 |
2/2✓ Branch 0 taken 32535 times.
✓ Branch 1 taken 168 times.
|
32703 | *y = SCALED_REF(refy_sb, top_offset, vs); |
401 | 32703 | *dx = SCALED_STEP(refp->scale[0]); | |
402 | 32703 | *dy = SCALED_STEP(refp->scale[1]); | |
403 | 32703 | } | |
404 | |||
405 | 32703 | static void emulated_edge_scaled(VVCLocalContext *lc, const uint8_t **src, ptrdiff_t *src_stride, int *src_height, | |
406 | 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) | ||
407 | { | ||
408 | 32703 | const int x_off = SCALED_INT(x); | |
409 | 32703 | const int y_off = SCALED_INT(y); | |
410 | 32703 | const int x_end = SCALED_INT(x + w * dx); | |
411 | 32703 | const int y_end = SCALED_INT(y + h * dy); | |
412 | 32703 | const int x_last = SCALED_INT(x + (w - 1) * dx); | |
413 | 32703 | const int y_last = SCALED_INT(y + (h - 1) * dy); | |
414 | 32703 | const int block_w = x_end - x_off + (x_end == x_last); | |
415 | 32703 | const int block_h = *src_height = y_end - y_off + (y_end == y_last); | |
416 | 32703 | const int wrap_enabled = 0; | |
417 | |||
418 |
4/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✓ Branch 2 taken 12262 times.
✓ Branch 3 taken 20441 times.
|
32703 | MC_EMULATED_EDGE(lc->edge_emu_buffer, src, src_stride, x_off, y_off); |
419 | 32703 | } | |
420 | |||
421 | 5946 | static void mc_scaled(VVCLocalContext *lc, int16_t *dst, const VVCRefPic *refp, const Mv *mv, | |
422 | int x_off, int y_off, const int block_w, const int block_h, const int c_idx) | ||
423 | { | ||
424 | 5946 | const VVCFrameContext *fc = lc->fc; | |
425 | 5946 | const PredictionUnit *pu = &lc->cu->pu; | |
426 | 5946 | const uint8_t *src = refp->ref->frame->data[c_idx]; | |
427 | 5946 | ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; | |
428 | 5946 | const int is_affine = pu->inter_affine_flag; | |
429 | 5946 | const int is_chroma = !!c_idx; | |
430 | 5946 | const int idx = av_log2(block_w) - 1; | |
431 | 5946 | const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); | |
432 | 5946 | const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); | |
433 | int x, y, dx, dy, src_height; | ||
434 | |||
435 | 5946 | scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); | |
436 | 5946 | emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); | |
437 | 5946 | fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w); | |
438 | 5946 | } | |
439 | |||
440 | 26757 | static void mc_uni_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp, | |
441 | const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx) | ||
442 | { | ||
443 | 26757 | const VVCFrameContext *fc = lc->fc; | |
444 | 26757 | const PredictionUnit *pu = &lc->cu->pu; | |
445 | 26757 | const uint8_t *src = refp->ref->frame->data[c_idx]; | |
446 | 26757 | ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; | |
447 | 26757 | const int lx = mvf->pred_flag - PF_L0; | |
448 | 26757 | const Mv *mv = &mvf->mv[lx]; | |
449 | 26757 | const int is_affine = pu->inter_affine_flag; | |
450 | 26757 | const int is_chroma = !!c_idx; | |
451 | 26757 | const int idx = av_log2(block_w) - 1; | |
452 | 26757 | const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); | |
453 | 26757 | const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); | |
454 | int denom, wx, ox, x, y, dx, dy, src_height; | ||
455 | |||
456 | 26757 | scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); | |
457 | 26757 | emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); | |
458 | |||
459 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26757 times.
|
26757 | if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { |
460 | ✗ | fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, | |
461 | x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w); | ||
462 | } else { | ||
463 | 26757 | fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, | |
464 | x, y, dx, dy, block_h, hf, vf, block_w); | ||
465 | } | ||
466 | 26757 | } | |
467 | |||
468 | 1086 | static void mc_bi_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
469 | const VVCRefPic *refp0, const VVCRefPic *refp1, const MvField *mvf, | ||
470 | const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx) | ||
471 | { | ||
472 | int denom, w0, w1, o0, o1; | ||
473 | 1086 | const VVCFrameContext *fc = lc->fc; | |
474 | 1086 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, lc->cu->pu.dmvr_flag); | |
475 | 1086 | const VVCRefPic *refps[] = { refp0, refp1 }; | |
476 | 1086 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
477 | |||
478 |
2/2✓ Branch 0 taken 2172 times.
✓ Branch 1 taken 1086 times.
|
3258 | for (int i = L0; i <= L1; i++) { |
479 | 2172 | const Mv *mv = mvf->mv + i; | |
480 | 2172 | const VVCRefPic *refp = refps[i]; | |
481 | |||
482 |
2/2✓ Branch 0 taken 2055 times.
✓ Branch 1 taken 117 times.
|
2172 | if (refp->is_scaled) |
483 | 2055 | mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx); | |
484 | else | ||
485 | 117 | mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx); | |
486 | } | ||
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (weight_flag) |
488 | ✗ | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
489 | else | ||
490 | 1086 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
491 | 1086 | } | |
492 | |||
493 | 2422408 | static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
494 | const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, | ||
495 | const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y) | ||
496 | { | ||
497 | 2422408 | const VVCFrameContext *fc = lc->fc; | |
498 | 2422408 | const uint8_t *src = ref->frame->data[LUMA]; | |
499 | 2422408 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
500 | 2422408 | uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET; | |
501 | 2422408 | const int idx = av_log2(block_w) - 1; | |
502 | 2422408 | const int lx = mvf->pred_flag - PF_L0; | |
503 | 2422408 | const Mv *mv = mvf->mv + lx; | |
504 | 2422408 | const int mx = mv->x & 0xf; | |
505 | 2422408 | const int my = mv->y & 0xf; | |
506 | 2422408 | const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx]; | |
507 | 2422408 | const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my]; | |
508 | int denom, wx, ox; | ||
509 | 2422408 | const int weight_flag = derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA); | |
510 | 2422408 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
511 | 2422408 | const int is_chroma = 0; | |
512 | |||
513 | 2422408 | x_off += mv->x >> 4; | |
514 | 2422408 | y_off += mv->y >> 4; | |
515 | |||
516 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2422408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2422408 times.
|
2422408 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
517 |
2/2✓ Branch 0 taken 2135792 times.
✓ Branch 1 taken 286616 times.
|
2422408 | if (cb_prof_flag) { |
518 | 2135792 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE); | |
519 | 2135792 | fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my); | |
520 |
2/2✓ Branch 0 taken 2121460 times.
✓ Branch 1 taken 14332 times.
|
2135792 | if (!weight_flag) |
521 | 2121460 | fc->vvcdsp.inter.apply_prof_uni(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y); | |
522 | else | ||
523 | 14332 | fc->vvcdsp.inter.apply_prof_uni_w(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y, denom, wx, ox); | |
524 | } else { | ||
525 |
2/2✓ Branch 0 taken 156368 times.
✓ Branch 1 taken 130248 times.
|
286616 | if (!weight_flag) |
526 | 156368 | fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w); | |
527 | else | ||
528 | 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); | |
529 | } | ||
530 | 2422408 | } | |
531 | |||
532 | 1876240 | static void luma_prof(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, | |
533 | const Mv *mv , const int x_off, const int y_off, const int block_w, const int block_h, const int lx) | ||
534 | { | ||
535 | 1876240 | const VVCFrameContext *fc = lc->fc; | |
536 | 1876240 | const PredictionUnit *pu = &lc->cu->pu; | |
537 | 1876240 | const int mx = mv->x & 0xf; | |
538 | 1876240 | const int my = mv->y & 0xf; | |
539 | 1876240 | const int ox = x_off + (mv->x >> 4); | |
540 | 1876240 | const int oy = y_off + (mv->y >> 4); | |
541 | 1876240 | const int idx = av_log2(block_w) - 1; | |
542 | 1876240 | const int is_chroma = 0; | |
543 | 1876240 | uint16_t *prof_tmp = lc->tmp2 + PROF_TEMP_OFFSET; | |
544 | 1876240 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
545 | 1876240 | const uint8_t *src = ref->frame->data[LUMA]; | |
546 | 1876240 | const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx]; | |
547 | 1876240 | const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my]; | |
548 | 1876240 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
549 | |||
550 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1876240 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1876240 times.
|
1876240 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); |
551 |
2/2✓ Branch 0 taken 507720 times.
✓ Branch 1 taken 1368520 times.
|
1876240 | if (!pu->cb_prof_flag[lx]) { |
552 | 507720 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); | |
553 | } else { | ||
554 | 1368520 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE); | |
555 | 1368520 | fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my); | |
556 | 1368520 | fc->vvcdsp.inter.apply_prof(dst, prof_tmp, pu->diff_mv_x[lx], pu->diff_mv_y[lx]); | |
557 | } | ||
558 | 1876240 | } | |
559 | |||
560 | 939656 | static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
561 | const VVCRefPic *ref0, const VVCRefPic *ref1, const MvField *mvf, const int x_off, const int y_off, | ||
562 | const int block_w, const int block_h) | ||
563 | { | ||
564 | 939656 | const VVCFrameContext *fc = lc->fc; | |
565 | 939656 | const VVCRefPic *refps[] = { ref0, ref1 }; | |
566 | 939656 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
567 | int denom, w0, w1, o0, o1; | ||
568 | 939656 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, LUMA, 0); | |
569 | |||
570 |
2/2✓ Branch 0 taken 1879312 times.
✓ Branch 1 taken 939656 times.
|
2818968 | for (int i = L0; i <= L1; i++) { |
571 | 1879312 | const VVCRefPic *refp = refps[i]; | |
572 | 1879312 | const Mv *mv = mvf->mv + i; | |
573 | |||
574 |
2/2✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 1876240 times.
|
1879312 | if (refp->is_scaled) |
575 | 3072 | mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, LUMA); | |
576 | else | ||
577 | 1876240 | luma_prof(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, i); | |
578 | } | ||
579 | |||
580 |
2/2✓ Branch 0 taken 275000 times.
✓ Branch 1 taken 664656 times.
|
939656 | if (weight_flag) |
581 | 275000 | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
582 | else | ||
583 | 664656 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
584 | 939656 | } | |
585 | |||
586 | 7694982 | static int pred_get_refs(const VVCLocalContext *lc, VVCRefPic *refp[2], const MvField *mv) | |
587 | { | ||
588 | 7694982 | RefPicList *rpl = lc->sc->rpl; | |
589 | |||
590 |
2/2✓ Branch 0 taken 15389964 times.
✓ Branch 1 taken 7694982 times.
|
23084946 | for (int mask = PF_L0; mask <= PF_L1; mask++) { |
591 |
2/2✓ Branch 0 taken 11523411 times.
✓ Branch 1 taken 3866553 times.
|
15389964 | if (mv->pred_flag & mask) { |
592 | 11523411 | const int lx = mask - PF_L0; | |
593 | 11523411 | refp[lx] = rpl[lx].refs + mv->ref_idx[lx]; | |
594 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11523411 times.
|
11523411 | if (!refp[lx]->ref) |
595 | ✗ | return AVERROR_INVALIDDATA; | |
596 | } | ||
597 | } | ||
598 | 7694982 | return 0; | |
599 | } | ||
600 | |||
601 | #define POS(c_idx, x, y) \ | ||
602 | &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \ | ||
603 | (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)] | ||
604 | |||
605 | 25615 | static void pred_gpm_blk(VVCLocalContext *lc) | |
606 | { | ||
607 | 25615 | const VVCFrameContext *fc = lc->fc; | |
608 | 25615 | const CodingUnit *cu = lc->cu; | |
609 | 25615 | const PredictionUnit *pu = &cu->pu; | |
610 | |||
611 | 25615 | const uint8_t angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx]; | |
612 | 25615 | const uint8_t weights_idx = ff_vvc_gpm_angle_to_weights_idx[angle_idx]; | |
613 | 25615 | const int w = av_log2(cu->cb_width) - 3; | |
614 | 25615 | const int h = av_log2(cu->cb_height) - 3; | |
615 | 25615 | const uint8_t off_x = ff_vvc_gpm_weights_offset_x[pu->gpm_partition_idx][h][w]; | |
616 | 25615 | const uint8_t off_y = ff_vvc_gpm_weights_offset_y[pu->gpm_partition_idx][h][w]; | |
617 | 25615 | const uint8_t mirror_type = ff_vvc_gpm_angle_to_mirror[angle_idx]; | |
618 | const uint8_t *weights; | ||
619 | |||
620 |
2/2✓ Branch 0 taken 23334 times.
✓ Branch 1 taken 2281 times.
|
25615 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1; |
621 | |||
622 | 25615 | int16_t *tmp[2] = {lc->tmp, lc->tmp1}; | |
623 | |||
624 |
2/2✓ Branch 0 taken 72283 times.
✓ Branch 1 taken 25615 times.
|
97898 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
625 | 72283 | const int hs = fc->ps.sps->hshift[c_idx]; | |
626 | 72283 | const int vs = fc->ps.sps->vshift[c_idx]; | |
627 | 72283 | const int x = lc->cu->x0 >> hs; | |
628 | 72283 | const int y = lc->cu->y0 >> vs; | |
629 | 72283 | const int width = cu->cb_width >> hs; | |
630 | 72283 | const int height = cu->cb_height >> vs; | |
631 | 72283 | uint8_t *dst = POS(c_idx, lc->cu->x0, lc->cu->y0); | |
632 | 72283 | ptrdiff_t dst_stride = fc->frame->linesize[c_idx]; | |
633 | |||
634 | 72283 | int step_x = 1 << hs; | |
635 | 72283 | int step_y = VVC_GPM_WEIGHT_SIZE << vs; | |
636 |
2/2✓ Branch 0 taken 44842 times.
✓ Branch 1 taken 27441 times.
|
72283 | if (!mirror_type) { |
637 | 44842 | weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + off_x]; | |
638 |
2/2✓ Branch 0 taken 11657 times.
✓ Branch 1 taken 15784 times.
|
27441 | } else if (mirror_type == 1) { |
639 | 11657 | step_x = -step_x; | |
640 | 11657 | weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + VVC_GPM_WEIGHT_SIZE - 1- off_x]; | |
641 | } else { | ||
642 | 15784 | step_y = -step_y; | |
643 | 15784 | weights = &ff_vvc_gpm_weights[weights_idx][(VVC_GPM_WEIGHT_SIZE - 1 - off_y) * VVC_GPM_WEIGHT_SIZE + off_x]; | |
644 | } | ||
645 | |||
646 |
2/2✓ Branch 0 taken 144566 times.
✓ Branch 1 taken 72283 times.
|
216849 | for (int i = 0; i < 2; i++) { |
647 | 144566 | const MvField *mv = pu->gpm_mv + i; | |
648 | 144566 | const int lx = mv->pred_flag - PF_L0; | |
649 | 144566 | VVCRefPic *refp = lc->sc->rpl[lx].refs + mv->ref_idx[lx]; | |
650 | |||
651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 144566 times.
|
144566 | if (!refp->ref) |
652 | ✗ | return; | |
653 |
2/2✓ Branch 0 taken 819 times.
✓ Branch 1 taken 143747 times.
|
144566 | if (refp->is_scaled) |
654 | 819 | mc_scaled(lc, tmp[i], refp, mv->mv + lx, x, y, width, height, c_idx); | |
655 | else | ||
656 | 143747 | mc(lc, tmp[i], refp->ref, mv->mv + lx, x, y, width, height, c_idx); | |
657 | } | ||
658 | 72283 | fc->vvcdsp.inter.put_gpm(dst, dst_stride, width, height, tmp[0], tmp[1], weights, step_x, step_y); | |
659 | } | ||
660 | 25615 | return; | |
661 | } | ||
662 | |||
663 | 41958 | static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0, | |
664 | const int width, const int height) | ||
665 | { | ||
666 | 41958 | const VVCFrameContext *fc = lc->fc; | |
667 | 41958 | const VVCSPS *sps = fc->ps.sps; | |
668 | 41958 | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); | |
669 | 41958 | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); | |
670 |
4/4✓ Branch 0 taken 4813 times.
✓ Branch 1 taken 37145 times.
✓ Branch 2 taken 3903 times.
✓ Branch 3 taken 910 times.
|
41958 | const int available_l = lc->ctb_left_flag || x0b; |
671 |
4/4✓ Branch 0 taken 6239 times.
✓ Branch 1 taken 35719 times.
✓ Branch 2 taken 5453 times.
✓ Branch 3 taken 786 times.
|
41958 | const int available_u = lc->ctb_up_flag || y0b; |
672 | 41958 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
673 | 41958 | int w = 1; | |
674 | |||
675 |
4/4✓ Branch 0 taken 41172 times.
✓ Branch 1 taken 786 times.
✓ Branch 2 taken 6027 times.
✓ Branch 3 taken 35145 times.
|
41958 | if (available_u &&fc->tab.mvf[((y0 - 1) >> MIN_PU_LOG2) * min_pu_width + ((x0 - 1 + width)>> MIN_PU_LOG2)].pred_flag == PF_INTRA) |
676 | 6027 | w++; | |
677 | |||
678 |
4/4✓ Branch 0 taken 41048 times.
✓ Branch 1 taken 910 times.
✓ Branch 2 taken 5759 times.
✓ Branch 3 taken 35289 times.
|
41958 | if (available_l && fc->tab.mvf[((y0 - 1 + height)>> MIN_PU_LOG2) * min_pu_width + ((x0 - 1) >> MIN_PU_LOG2)].pred_flag == PF_INTRA) |
679 | 5759 | w++; | |
680 | |||
681 | 41958 | return w; | |
682 | } | ||
683 | |||
684 | 3333452 | static void pred_regular(VVCLocalContext *lc, const MvField *mvf, const MvField *orig_mvf, | |
685 | const int x0, const int y0, const int sbw, const int sbh, const int sb_bdof_flag, const int c_start) | ||
686 | { | ||
687 | 3333452 | const VVCFrameContext *fc = lc->fc; | |
688 |
2/2✓ Branch 0 taken 3305165 times.
✓ Branch 1 taken 28287 times.
|
3333452 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? CR : LUMA; |
689 | VVCRefPic *refp[2]; | ||
690 | |||
691 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3333452 times.
|
3333452 | if (pred_get_refs(lc, refp, mvf) < 0) |
692 | ✗ | return; | |
693 | |||
694 |
2/2✓ Branch 0 taken 8754476 times.
✓ Branch 1 taken 3333452 times.
|
12087928 | for (int c_idx = c_start; c_idx <= c_end; c_idx++) { |
695 | 8754476 | uint8_t *dst = POS(c_idx, x0, y0); | |
696 | 8754476 | const ptrdiff_t dst_stride = fc->frame->linesize[c_idx]; | |
697 | 8754476 | const int hs = fc->ps.sps->hshift[c_idx]; | |
698 | 8754476 | const int vs = fc->ps.sps->vshift[c_idx]; | |
699 | 8754476 | const int x = x0 >> hs; | |
700 | 8754476 | const int y = y0 >> vs; | |
701 | 8754476 | const int w = sbw >> hs; | |
702 | 8754476 | const int h = sbh >> vs; | |
703 | 8754476 | const int is_luma = !c_idx; | |
704 |
6/6✓ Branch 0 taken 46424 times.
✓ Branch 1 taken 8708052 times.
✓ Branch 2 taken 30738 times.
✓ Branch 3 taken 15686 times.
✓ Branch 4 taken 26272 times.
✓ Branch 5 taken 4466 times.
|
8754476 | const int do_ciip = lc->cu->ciip_flag && (is_luma || (w > 2)); |
705 |
2/2✓ Branch 0 taken 41958 times.
✓ Branch 1 taken 8712518 times.
|
8754476 | uint8_t *inter = do_ciip ? (uint8_t *)lc->ciip_tmp : dst; |
706 |
2/2✓ Branch 0 taken 8712518 times.
✓ Branch 1 taken 41958 times.
|
8754476 | const ptrdiff_t inter_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst_stride; |
707 |
4/4✓ Branch 0 taken 2144146 times.
✓ Branch 1 taken 6610330 times.
✓ Branch 2 taken 348253 times.
✓ Branch 3 taken 1795893 times.
|
8754476 | const int do_bdof = is_luma && sb_bdof_flag; |
708 | |||
709 |
2/2✓ Branch 0 taken 3458937 times.
✓ Branch 1 taken 5295539 times.
|
8754476 | if (mvf->pred_flag != PF_BI) { |
710 | 3458937 | const int lx = mvf->pred_flag - PF_L0; | |
711 | |||
712 |
2/2✓ Branch 0 taken 10749 times.
✓ Branch 1 taken 3448188 times.
|
3458937 | if (refp[lx]->is_scaled) { |
713 | 10749 | mc_uni_scaled(lc, inter, inter_stride, refp[lx], mvf, | |
714 | x, y, w, h, c_idx); | ||
715 | } else { | ||
716 | 3448188 | mc_uni(lc, inter, inter_stride, refp[lx]->ref, mvf, | |
717 | x, y, w, h, c_idx); | ||
718 | } | ||
719 | } else { | ||
720 |
4/4✓ Branch 0 taken 5294462 times.
✓ Branch 1 taken 1077 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 5294453 times.
|
5295539 | if (refp[L0]->is_scaled || refp[L1]->is_scaled) { |
721 | 1086 | mc_bi_scaled(lc, inter, inter_stride, refp[L0], refp[L1], mvf, | |
722 | x, y, w, h, c_idx); | ||
723 | } else { | ||
724 | 5294453 | mc_bi(lc, inter, inter_stride, refp[L0]->ref, refp[L1]->ref, mvf, orig_mvf, | |
725 | x, y, w, h, c_idx, do_bdof); | ||
726 | } | ||
727 | } | ||
728 |
2/2✓ Branch 0 taken 41958 times.
✓ Branch 1 taken 8712518 times.
|
8754476 | if (do_ciip) { |
729 | 41958 | const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh); | |
730 | 41958 | fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, c_idx); | |
731 |
4/4✓ Branch 0 taken 15686 times.
✓ Branch 1 taken 26272 times.
✓ Branch 2 taken 8298 times.
✓ Branch 3 taken 7388 times.
|
41958 | if (!c_idx && lc->sc->sh.r->sh_lmcs_used_flag) |
732 | 8298 | fc->vvcdsp.lmcs.filter(inter, inter_stride, w, h, &fc->ps.lmcs.fwd_lut); | |
733 | 41958 | fc->vvcdsp.inter.put_ciip(dst, dst_stride, w, h, inter, inter_stride, intra_weight); | |
734 | } | ||
735 | } | ||
736 | } | ||
737 | |||
738 | // 8.5.3.5 Parametric motion vector refinement process | ||
739 | 493420 | static int parametric_mv_refine(const int *sad, const int stride) | |
740 | { | ||
741 | 493420 | const int sad_minus = sad[-stride]; | |
742 | 493420 | const int sad_center = sad[0]; | |
743 | 493420 | const int sad_plus = sad[stride]; | |
744 | int dmvc; | ||
745 | 493420 | int denom = (( sad_minus + sad_plus) - (sad_center << 1 ) ) << 3; | |
746 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 493420 times.
|
493420 | if (!denom) |
747 | ✗ | dmvc = 0; | |
748 | else { | ||
749 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 493362 times.
|
493420 | if (sad_minus == sad_center) |
750 | 58 | dmvc = -8; | |
751 |
2/2✓ Branch 0 taken 239 times.
✓ Branch 1 taken 493123 times.
|
493362 | else if (sad_plus == sad_center) |
752 | 239 | dmvc = 8; | |
753 | else { | ||
754 | 493123 | int num = ( sad_minus - sad_plus ) * (1 << 4); | |
755 | 493123 | int sign_num = 0; | |
756 | 493123 | int quotient = 0; | |
757 | 493123 | int counter = 3; | |
758 |
2/2✓ Branch 0 taken 249591 times.
✓ Branch 1 taken 243532 times.
|
493123 | if (num < 0 ) { |
759 | 249591 | num = - num; | |
760 | 249591 | sign_num = 1; | |
761 | } | ||
762 |
2/2✓ Branch 0 taken 1479369 times.
✓ Branch 1 taken 493123 times.
|
1972492 | while (counter > 0) { |
763 | 1479369 | counter = counter - 1; | |
764 | 1479369 | quotient = quotient << 1; | |
765 |
2/2✓ Branch 0 taken 438853 times.
✓ Branch 1 taken 1040516 times.
|
1479369 | if ( num >= denom ) { |
766 | 438853 | num = num - denom; | |
767 | 438853 | quotient = quotient + 1; | |
768 | } | ||
769 | 1479369 | denom = (denom >> 1); | |
770 | } | ||
771 |
2/2✓ Branch 0 taken 249591 times.
✓ Branch 1 taken 243532 times.
|
493123 | if (sign_num == 1 ) |
772 | 249591 | dmvc = -quotient; | |
773 | else | ||
774 | 243532 | dmvc = quotient; | |
775 | } | ||
776 | } | ||
777 | 493420 | return dmvc; | |
778 | } | ||
779 | |||
780 | #define SAD_ARRAY_SIZE 5 | ||
781 | //8.5.3 Decoder-side motion vector refinement process | ||
782 | 983458 | static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag, | |
783 | const VVCFrame *ref0, const VVCFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h) | ||
784 | { | ||
785 | 983458 | const VVCFrameContext *fc = lc->fc; | |
786 | 983458 | const int sr_range = 2; | |
787 | 983458 | const VVCFrame *refs[] = { ref0, ref1 }; | |
788 | 983458 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
789 | int sad[SAD_ARRAY_SIZE][SAD_ARRAY_SIZE]; | ||
790 | int min_dx, min_dy, min_sad, dx, dy; | ||
791 | |||
792 | 983458 | *orig_mv = *mvf; | |
793 | 983458 | min_dx = min_dy = dx = dy = 2; | |
794 | |||
795 |
2/2✓ Branch 0 taken 1966916 times.
✓ Branch 1 taken 983458 times.
|
2950374 | for (int i = L0; i <= L1; i++) { |
796 | 1966916 | const int pred_w = block_w + 2 * sr_range; | |
797 | 1966916 | const int pred_h = block_h + 2 * sr_range; | |
798 | 1966916 | const Mv *mv = mvf->mv + i; | |
799 | 1966916 | const int mx = mv->x & 0xf; | |
800 | 1966916 | const int my = mv->y & 0xf; | |
801 | 1966916 | const int ox = x_off + (mv->x >> 4) - sr_range; | |
802 | 1966916 | const int oy = y_off + (mv->y >> 4) - sr_range; | |
803 | 1966916 | const VVCFrame *ref = refs[i]; | |
804 | 1966916 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
805 | 1966916 | const uint8_t *src = ref->frame->data[LUMA]; | |
806 | 1966916 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
807 | |||
808 | 1966916 | MC_EMULATED_EDGE_BILINEAR(lc->edge_emu_buffer, &src, &src_stride, ox, oy); | |
809 | 1966916 | fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w); | |
810 | } | ||
811 | |||
812 | 983458 | min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h); | |
813 | 983458 | min_sad -= min_sad >> 2; | |
814 | 983458 | sad[dy][dx] = min_sad; | |
815 | |||
816 |
2/2✓ Branch 0 taken 447918 times.
✓ Branch 1 taken 535540 times.
|
983458 | if (min_sad >= block_w * block_h) { |
817 | int dmv[2]; | ||
818 | // 8.5.3.4 Array entry selection process | ||
819 |
2/2✓ Branch 0 taken 2239590 times.
✓ Branch 1 taken 447918 times.
|
2687508 | for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) { |
820 |
2/2✓ Branch 0 taken 11197950 times.
✓ Branch 1 taken 2239590 times.
|
13437540 | for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) { |
821 |
4/4✓ Branch 0 taken 2239590 times.
✓ Branch 1 taken 8958360 times.
✓ Branch 2 taken 1791672 times.
✓ Branch 3 taken 447918 times.
|
11197950 | if (dx != sr_range || dy != sr_range) { |
822 | 10750032 | sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, dy, block_w, block_h); | |
823 |
2/2✓ Branch 0 taken 642981 times.
✓ Branch 1 taken 10107051 times.
|
10750032 | if (sad[dy][dx] < min_sad) { |
824 | 642981 | min_sad = sad[dy][dx]; | |
825 | 642981 | min_dx = dx; | |
826 | 642981 | min_dy = dy; | |
827 | } | ||
828 | } | ||
829 | } | ||
830 | } | ||
831 | 447918 | dmv[0] = (min_dx - sr_range) * (1 << 4); | |
832 | 447918 | dmv[1] = (min_dy - sr_range) * (1 << 4); | |
833 |
8/8✓ Branch 0 taken 371148 times.
✓ Branch 1 taken 76770 times.
✓ Branch 2 taken 307045 times.
✓ Branch 3 taken 64103 times.
✓ Branch 4 taken 255077 times.
✓ Branch 5 taken 51968 times.
✓ Branch 6 taken 246710 times.
✓ Branch 7 taken 8367 times.
|
447918 | if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) { |
834 | 246710 | dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1); | |
835 | 246710 | dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE); | |
836 | } | ||
837 | |||
838 |
2/2✓ Branch 0 taken 895836 times.
✓ Branch 1 taken 447918 times.
|
1343754 | for (int i = L0; i <= L1; i++) { |
839 | 895836 | Mv *mv = mvf->mv + i; | |
840 | 895836 | mv->x += (1 - 2 * i) * dmv[0]; | |
841 | 895836 | mv->y += (1 - 2 * i) * dmv[1]; | |
842 | 895836 | ff_vvc_clip_mv(mv); | |
843 | } | ||
844 | } | ||
845 |
2/2✓ Branch 0 taken 700645 times.
✓ Branch 1 taken 282813 times.
|
983458 | if (min_sad < 2 * block_w * block_h) { |
846 | 700645 | *sb_bdof_flag = 0; | |
847 | } | ||
848 | 983458 | } | |
849 | |||
850 | 983458 | static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0, | |
851 | const int width, const int height, const MvField *mvf) | ||
852 | |||
853 | { | ||
854 | 983458 | const VVCPPS *pps = fc->ps.pps; | |
855 | |||
856 |
2/2✓ Branch 0 taken 3891852 times.
✓ Branch 1 taken 983458 times.
|
4875310 | for (int y = y0; y < y0 + height; y += MIN_PU_SIZE) { |
857 |
2/2✓ Branch 0 taken 15433624 times.
✓ Branch 1 taken 3891852 times.
|
19325476 | for (int x = x0; x < x0 + width; x += MIN_PU_SIZE) { |
858 | 15433624 | const int idx = pps->min_pu_width * (y >> MIN_PU_LOG2) + (x >> MIN_PU_LOG2); | |
859 | 15433624 | fc->ref->tab_dmvr_mvf[idx] = *mvf; | |
860 | } | ||
861 | } | ||
862 | 983458 | } | |
863 | |||
864 | 2144146 | static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag, | |
865 | const int x0, const int y0, const int sbw, const int sbh) | ||
866 | { | ||
867 | 2144146 | VVCFrameContext *fc = lc->fc; | |
868 | 2144146 | const PredictionUnit *pu = &lc->cu->pu; | |
869 | |||
870 | 2144146 | *orig_mv = *mv = *ff_vvc_get_mvf(fc, x0, y0); | |
871 |
2/2✓ Branch 0 taken 1048898 times.
✓ Branch 1 taken 1095248 times.
|
2144146 | if (pu->bdof_flag) |
872 | 1048898 | *sb_bdof_flag = 1; | |
873 |
2/2✓ Branch 0 taken 983458 times.
✓ Branch 1 taken 1160688 times.
|
2144146 | if (pu->dmvr_flag) { |
874 | VVCRefPic *refp[2]; | ||
875 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 983458 times.
|
983458 | if (pred_get_refs(lc, refp, mv) < 0) |
876 | ✗ | return; | |
877 | 983458 | dmvr_mv_refine(lc, mv, orig_mv, sb_bdof_flag, refp[L0]->ref, refp[L1]->ref, x0, y0, sbw, sbh); | |
878 | 983458 | set_dmvr_info(fc, x0, y0, sbw, sbh, mv); | |
879 | } | ||
880 | } | ||
881 | |||
882 | 379414 | static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip) | |
883 | { | ||
884 | 379414 | const CodingUnit *cu = lc->cu; | |
885 | 379414 | PredictionUnit *pu = &lc->cu->pu; | |
886 | 379414 | const MotionInfo *mi = &pu->mi; | |
887 | MvField mv, orig_mv; | ||
888 | 379414 | int sbw, sbh, sb_bdof_flag = 0; | |
889 | |||
890 |
4/4✓ Branch 0 taken 31372 times.
✓ Branch 1 taken 348042 times.
✓ Branch 2 taken 15686 times.
✓ Branch 3 taken 15686 times.
|
379414 | if (cu->ciip_flag && skip_ciip) |
891 | 15686 | return; | |
892 | |||
893 | 363728 | sbw = cu->cb_width / mi->num_sb_x; | |
894 | 363728 | sbh = cu->cb_height / mi->num_sb_y; | |
895 | |||
896 |
2/2✓ Branch 0 taken 588992 times.
✓ Branch 1 taken 363728 times.
|
952720 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
897 |
2/2✓ Branch 0 taken 2144146 times.
✓ Branch 1 taken 588992 times.
|
2733138 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
898 | 2144146 | const int x0 = cu->x0 + sbx * sbw; | |
899 | 2144146 | const int y0 = cu->y0 + sby * sbh; | |
900 | |||
901 |
2/2✓ Branch 0 taken 15686 times.
✓ Branch 1 taken 2128460 times.
|
2144146 | if (cu->ciip_flag) |
902 | 15686 | ff_vvc_set_neighbour_available(lc, x0, y0, sbw, sbh); | |
903 | |||
904 | 2144146 | derive_sb_mv(lc, &mv, &orig_mv, &sb_bdof_flag, x0, y0, sbw, sbh); | |
905 | 2144146 | pred_regular(lc, &mv, &orig_mv, x0, y0, sbw, sbh, sb_bdof_flag, LUMA); | |
906 | } | ||
907 | } | ||
908 | } | ||
909 | |||
910 | 1189306 | static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv, | |
911 | const int x0, const int y0, const int sbw, const int sbh) | ||
912 | { | ||
913 | 1189306 | const int hs = fc->ps.sps->hshift[1]; | |
914 | 1189306 | const int vs = fc->ps.sps->vshift[1]; | |
915 | 1189306 | const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh); | |
916 | 1189306 | *mvc = *mv; | |
917 | |||
918 | // Due to different pred_flag, one of the motion vectors may have an invalid value. | ||
919 | // Cast them to an unsigned type to avoid undefined behavior. | ||
920 | 1189306 | mvc->mv[0].x += (unsigned int)mv2->mv[0].x; | |
921 | 1189306 | mvc->mv[0].y += (unsigned int)mv2->mv[0].y; | |
922 | 1189306 | mvc->mv[1].x += (unsigned int)mv2->mv[1].x; | |
923 | 1189306 | mvc->mv[1].y += (unsigned int)mv2->mv[1].y; | |
924 | 1189306 | ff_vvc_round_mv(mvc->mv + 0, 0, 1); | |
925 | 1189306 | ff_vvc_round_mv(mvc->mv + 1, 0, 1); | |
926 | 1189306 | } | |
927 | |||
928 | 34723 | static void pred_affine_blk(VVCLocalContext *lc) | |
929 | { | ||
930 | 34723 | const VVCFrameContext *fc = lc->fc; | |
931 | 34723 | const CodingUnit *cu = lc->cu; | |
932 | 34723 | const PredictionUnit *pu = &cu->pu; | |
933 | 34723 | const MotionInfo *mi = &pu->mi; | |
934 | 34723 | const int x0 = cu->x0; | |
935 | 34723 | const int y0 = cu->y0; | |
936 | 34723 | const int sbw = cu->cb_width / mi->num_sb_x; | |
937 | 34723 | const int sbh = cu->cb_height / mi->num_sb_y; | |
938 | 34723 | const int hs = fc->ps.sps->hshift[1]; | |
939 | 34723 | const int vs = fc->ps.sps->vshift[1]; | |
940 | 34723 | const int dst_stride = fc->frame->linesize[LUMA]; | |
941 | |||
942 |
2/2✓ Branch 0 taken 274454 times.
✓ Branch 1 taken 34723 times.
|
309177 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
943 |
2/2✓ Branch 0 taken 3378072 times.
✓ Branch 1 taken 274454 times.
|
3652526 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
944 | 3378072 | const int x = x0 + sbx * sbw; | |
945 | 3378072 | const int y = y0 + sby * sbh; | |
946 | |||
947 | 3378072 | uint8_t *dst0 = POS(0, x, y); | |
948 | 3378072 | const MvField *mv = ff_vvc_get_mvf(fc, x, y); | |
949 | VVCRefPic *refp[2]; | ||
950 | |||
951 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3378072 times.
|
3378072 | if (pred_get_refs(lc, refp, mv) < 0) |
952 | ✗ | return; | |
953 | |||
954 |
2/2✓ Branch 0 taken 2438416 times.
✓ Branch 1 taken 939656 times.
|
3378072 | if (mi->pred_flag != PF_BI) { |
955 | 2438416 | const int lx = mi->pred_flag - PF_L0; | |
956 |
2/2✓ Branch 0 taken 16008 times.
✓ Branch 1 taken 2422408 times.
|
2438416 | if (refp[lx]->is_scaled) { |
957 | 16008 | mc_uni_scaled(lc, dst0, dst_stride, refp[lx], mv, x, y, sbw, sbh, LUMA); | |
958 | } else { | ||
959 | 2422408 | luma_prof_uni(lc, dst0, dst_stride, refp[lx]->ref, | |
960 | 2422408 | mv, x, y, sbw, sbh, pu->cb_prof_flag[lx], | |
961 | 2422408 | pu->diff_mv_x[lx], pu->diff_mv_y[lx]); | |
962 | } | ||
963 | } else { | ||
964 | 939656 | luma_prof_bi(lc, dst0, dst_stride, refp[L0], refp[L1], mv, x, y, sbw, sbh); | |
965 | } | ||
966 |
2/2✓ Branch 0 taken 3339964 times.
✓ Branch 1 taken 38108 times.
|
3378072 | if (fc->ps.sps->r->sps_chroma_format_idc) { |
967 |
4/4✓ Branch 0 taken 1906192 times.
✓ Branch 1 taken 1433772 times.
✓ Branch 2 taken 1189306 times.
✓ Branch 3 taken 716886 times.
|
3339964 | if (!av_zero_extend(sby, vs) && !av_zero_extend(sbx, hs)) { |
968 | MvField mvc; | ||
969 | |||
970 | 1189306 | derive_affine_mvc(&mvc, fc, mv, x, y, sbw, sbh); | |
971 | 1189306 | pred_regular(lc, &mvc, NULL, x, y, sbw << hs, sbh << vs, 0, CB); | |
972 | } | ||
973 | } | ||
974 | |||
975 | } | ||
976 | } | ||
977 | } | ||
978 | |||
979 | 424066 | static void predict_inter(VVCLocalContext *lc) | |
980 | { | ||
981 | 424066 | const VVCFrameContext *fc = lc->fc; | |
982 | 424066 | const CodingUnit *cu = lc->cu; | |
983 | 424066 | const PredictionUnit *pu = &cu->pu; | |
984 | |||
985 |
2/2✓ Branch 0 taken 25615 times.
✓ Branch 1 taken 398451 times.
|
424066 | if (pu->merge_gpm_flag) |
986 | 25615 | pred_gpm_blk(lc); | |
987 |
2/2✓ Branch 0 taken 34723 times.
✓ Branch 1 taken 363728 times.
|
398451 | else if (pu->inter_affine_flag) |
988 | 34723 | pred_affine_blk(lc); | |
989 | else | ||
990 | 363728 | pred_regular_blk(lc, 1); //intra block is not ready yet, skip ciip | |
991 | |||
992 |
4/4✓ Branch 0 taken 185652 times.
✓ Branch 1 taken 238414 times.
✓ Branch 2 taken 177354 times.
✓ Branch 3 taken 8298 times.
|
424066 | if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) { |
993 | 177354 | uint8_t* dst0 = POS(0, cu->x0, cu->y0); | |
994 | 177354 | fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut); | |
995 | } | ||
996 | 424066 | } | |
997 | |||
998 | 1232069 | static int has_inter_luma(const CodingUnit *cu) | |
999 | { | ||
1000 |
4/6✓ Branch 0 taken 808003 times.
✓ Branch 1 taken 424066 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 808003 times.
✓ Branch 4 taken 424066 times.
✗ Branch 5 not taken.
|
1232069 | return (cu->pred_mode == MODE_INTER || cu->pred_mode == MODE_SKIP) && cu->tree_type != DUAL_TREE_CHROMA; |
1001 | } | ||
1002 | |||
1003 | 46705 | int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs) | |
1004 | { | ||
1005 | 46705 | const VVCFrameContext *fc = lc->fc; | |
1006 | 46705 | CodingUnit *cu = fc->tab.cus[rs]; | |
1007 | |||
1008 |
2/2✓ Branch 0 taken 1232069 times.
✓ Branch 1 taken 46705 times.
|
1278774 | while (cu) { |
1009 | 1232069 | lc->cu = cu; | |
1010 |
2/2✓ Branch 1 taken 424066 times.
✓ Branch 2 taken 808003 times.
|
1232069 | if (has_inter_luma(cu)) |
1011 | 424066 | predict_inter(lc); | |
1012 | 1232069 | cu = cu->next; | |
1013 | } | ||
1014 | |||
1015 | 46705 | return 0; | |
1016 | } | ||
1017 | |||
1018 | 15686 | void ff_vvc_predict_ciip(VVCLocalContext *lc) | |
1019 | { | ||
1020 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15686 times.
|
15686 | av_assert0(lc->cu->ciip_flag); |
1021 | |||
1022 | //todo: refact out ciip from pred_regular_blk | ||
1023 | 15686 | pred_regular_blk(lc, 0); | |
1024 | 15686 | } | |
1025 | |||
1026 | #undef POS | ||
1027 |