FFmpeg
inter.c
Go to the documentation of this file.
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 static void subpic_offset(int *x_off, int *y_off,
34  const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_chroma)
35 {
36  *x_off -= pps->subpic_x[subpic_idx] >> sps->hshift[is_chroma];
37  *y_off -= pps->subpic_y[subpic_idx] >> sps->vshift[is_chroma];
38 }
39 
40 static void subpic_width_height(int *pic_width, int *pic_height,
41  const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_chroma)
42 {
43  *pic_width = pps->subpic_width[subpic_idx] >> sps->hshift[is_chroma];
44  *pic_height = pps->subpic_height[subpic_idx] >> sps->vshift[is_chroma];
45 }
46 
47 static int emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame,
48  int x_off, int y_off, const int block_w, const int block_h, const int is_chroma)
49 {
50  const VVCFrameContext *fc = lc->fc;
51  const VVCSPS *sps = src_frame->sps;
52  const VVCPPS *pps = src_frame->pps;
53  const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
54  const int extra_before = is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE;
55  const int extra_after = is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER;
56  const int extra = is_chroma ? CHROMA_EXTRA : LUMA_EXTRA;
57  int pic_width, pic_height;
58 
59  subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, is_chroma);
60  subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, is_chroma);
61 
62  if (x_off < extra_before || y_off < extra_before ||
63  x_off >= pic_width - block_w - extra_after ||
64  y_off >= pic_height - block_h - extra_after) {
65  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << fc->ps.sps->pixel_shift;
66  int offset = extra_before * *src_stride + (extra_before << fc->ps.sps->pixel_shift);
67  int buf_offset = extra_before * edge_emu_stride + (extra_before << fc->ps.sps->pixel_shift);
68 
69  fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride,
70  block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before,
71  pic_width, pic_height);
72 
73  *src = dst + buf_offset;
74  *src_stride = edge_emu_stride;
75  return 1;
76  }
77  return 0;
78 }
79 
80 static void emulated_edge_dmvr(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride,
81  int x_sb, int y_sb, int x_off, int y_off, const int block_w, const int block_h, const int is_chroma)
82 {
83  const VVCFrameContext *fc = lc->fc;
84  const VVCSPS *sps = fc->ps.sps;
85  const VVCPPS *pps = fc->ps.pps;
86  const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
87  const int extra_before = is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE;
88  const int extra_after = is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER;
89  const int extra = is_chroma ? CHROMA_EXTRA : LUMA_EXTRA;
90  int pic_width, pic_height;
91 
92  subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, is_chroma);
93  subpic_offset(&x_sb, &y_sb, sps, pps, subpic_idx, is_chroma);
94  subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, is_chroma);
95 
96  if (x_off < extra_before || y_off < extra_before ||
97  x_off >= pic_width - block_w - extra_after ||
98  y_off >= pic_height - block_h - extra_after||
99  (x_off != x_sb || y_off != y_sb)) {
100  const int ps = fc->ps.sps->pixel_shift;
101  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps;
102  const int offset = extra_before * *src_stride + (extra_before << ps);
103  const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps);
104 
105  const int start_x = FFMIN(FFMAX(x_sb - extra_before, 0), pic_width - 1);
106  const int start_y = FFMIN(FFMAX(y_sb - extra_before, 0), pic_height - 1);
107  const int width = FFMAX(FFMIN(pic_width, x_sb + block_w + extra_after) - start_x, 1);
108  const int height = FFMAX(FFMIN(pic_height, y_sb + block_h + extra_after) - start_y, 1);
109 
110  fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + extra, block_h + extra,
111  x_off - start_x - extra_before, y_off - start_y - extra_before, width, height);
112 
113  *src = dst + buf_offset;
114  *src_stride = edge_emu_stride;
115  }
116 }
117 
118 static void emulated_edge_bilinear(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride,
119  int x_off, int y_off, const int block_w, const int block_h)
120 {
121  const VVCFrameContext *fc = lc->fc;
122  const VVCSPS *sps = fc->ps.sps;
123  const VVCPPS *pps = fc->ps.pps;
124  const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
125  int pic_width, pic_height;
126 
127  subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, 0);
128  subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, 0);
129 
130  if (x_off < BILINEAR_EXTRA_BEFORE || y_off < BILINEAR_EXTRA_BEFORE ||
131  x_off >= pic_width - block_w - BILINEAR_EXTRA_AFTER ||
132  y_off >= pic_height - block_h - BILINEAR_EXTRA_AFTER) {
133  const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << fc->ps.sps->pixel_shift;
134  const int offset = BILINEAR_EXTRA_BEFORE * *src_stride + (BILINEAR_EXTRA_BEFORE << fc->ps.sps->pixel_shift);
135  const int buf_offset = BILINEAR_EXTRA_BEFORE * edge_emu_stride + (BILINEAR_EXTRA_BEFORE << fc->ps.sps->pixel_shift);
136 
137  fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + BILINEAR_EXTRA, block_h + BILINEAR_EXTRA,
138  x_off - BILINEAR_EXTRA_BEFORE, y_off - BILINEAR_EXTRA_BEFORE, pic_width, pic_height);
139 
140  *src = dst + buf_offset;
141  *src_stride = edge_emu_stride;
142  }
143 }
144 
145 #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off) \
146  emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, block_w, block_h, is_chroma)
147 
148 #define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \
149  emulated_edge_dmvr(lc, dst, src, src_stride, x_sb, y_sb, x_off, y_off, block_w, block_h, is_chroma)
150 
151 #define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \
152  emulated_edge_bilinear(lc, dst, src, src_stride, x_off, y_off, pred_w, pred_h)
153 
154 // part of 8.5.6.6 Weighted sample prediction process
155 static int derive_weight_uni(int *denom, int *wx, int *ox,
156  const VVCLocalContext *lc, const MvField *mvf, const int c_idx)
157 {
158  const VVCFrameContext *fc = lc->fc;
159  const VVCPPS *pps = fc->ps.pps;
160  const VVCSH *sh = &lc->sc->sh;
161  const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) ||
162  (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag);
163  if (weight_flag) {
164  const int lx = mvf->pred_flag - PF_L0;
165  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
166 
167  *denom = w->log2_denom[c_idx > 0];
168  *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]];
169  *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]];
170  }
171  return weight_flag;
172 }
173 
174 // part of 8.5.6.6 Weighted sample prediction process
175 static int derive_weight(int *denom, int *w0, int *w1, int *o0, int *o1,
176  const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag)
177 {
178  const VVCFrameContext *fc = lc->fc;
179  const VVCPPS *pps = fc->ps.pps;
180  const VVCSH *sh = &lc->sc->sh;
181  const int bcw_idx = mvf->bcw_idx;
182  const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) ||
183  (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag);
184  if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag))
185  return 0;
186 
187  if (bcw_idx) {
188  *denom = 2;
189  *w1 = bcw_w_lut[bcw_idx];
190  *w0 = 8 - *w1;
191  *o0 = *o1 = 0;
192  } else {
193  const VVCPPS *pps = fc->ps.pps;
194  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
195 
196  *denom = w->log2_denom[c_idx > 0];
197  *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]];
198  *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]];
199  *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]];
200  *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]];
201  }
202  return 1;
203 }
204 
205 #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac])
206 
207 static void mc(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv,
208  int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
209 {
210  const VVCFrameContext *fc = lc->fc;
211  const PredictionUnit *pu = &lc->cu->pu;
212  const uint8_t *src = ref->frame->data[c_idx];
213  ptrdiff_t src_stride = ref->frame->linesize[c_idx];
214  const int is_chroma = !!c_idx;
215  const int hs = fc->ps.sps->hshift[c_idx];
216  const int vs = fc->ps.sps->vshift[c_idx];
217  const int idx = av_log2(block_w) - 1;
218  const intptr_t mx = av_mod_uintp2(mv->x, 4 + hs) << (is_chroma - hs);
219  const intptr_t my = av_mod_uintp2(mv->y, 4 + vs) << (is_chroma - vs);
220  const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx;
221  const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
222  const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
223 
224  x_off += mv->x >> (4 + hs);
225  y_off += mv->y >> (4 + vs);
226  src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
227 
228  MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
229  fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
230 }
231 
232 static void mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
233  const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
234  const int c_idx)
235 {
236  const VVCFrameContext *fc = lc->fc;
237  const PredictionUnit *pu = &lc->cu->pu;
238  const uint8_t *src = ref->frame->data[c_idx];
239  ptrdiff_t src_stride = ref->frame->linesize[c_idx];
240  const int lx = mvf->pred_flag - PF_L0;
241  const int hs = fc->ps.sps->hshift[c_idx];
242  const int vs = fc->ps.sps->vshift[c_idx];
243  const int idx = av_log2(block_w) - 1;
244  const Mv *mv = &mvf->mv[lx];
245  const int is_chroma = !!c_idx;
246  const intptr_t mx = av_mod_uintp2(mv->x, 4 + hs) << (is_chroma - hs);
247  const intptr_t my = av_mod_uintp2(mv->y, 4 + vs) << (is_chroma - vs);
248  const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx;
249  const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
250  const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
251  int denom, wx, ox;
252 
253  x_off += mv->x >> (4 + hs);
254  y_off += mv->y >> (4 + vs);
255  src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
256 
257  MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
258  if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) {
259  fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
260  block_h, denom, wx, ox, hf, vf, block_w);
261  } else {
262  fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
263  block_h, hf, vf, block_w);
264  }
265 }
266 
267 static void mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
268  const VVCFrame *ref0, const VVCFrame *ref1, const MvField *mvf, const MvField *orig_mv,
269  const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx,
270  const int sb_bdof_flag)
271 {
272  const VVCFrameContext *fc = lc->fc;
273  const PredictionUnit *pu = &lc->cu->pu;
274  const int hs = fc->ps.sps->hshift[c_idx];
275  const int vs = fc->ps.sps->vshift[c_idx];
276  const int idx = av_log2(block_w) - 1;
277  const VVCFrame *refs[] = { ref0, ref1 };
278  int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET };
279  int denom, w0, w1, o0, o1;
280  const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, pu->dmvr_flag);
281  const int is_chroma = !!c_idx;
282  const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx;
283 
284  for (int i = L0; i <= L1; i++) {
285  const Mv *mv = mvf->mv + i;
286  const int mx = av_mod_uintp2(mv->x, 4 + hs) << (is_chroma - hs);
287  const int my = av_mod_uintp2(mv->y, 4 + vs) << (is_chroma - vs);
288  const int ox = x_off + (mv->x >> (4 + hs));
289  const int oy = y_off + (mv->y >> (4 + vs));
290  const VVCFrame *ref = refs[i];
291  ptrdiff_t src_stride = ref->frame->linesize[c_idx];
292  const uint8_t *src = ref->frame->data[c_idx] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
293  const int8_t *hf = INTER_FILTER(hpel_if_idx, mx);
294  const int8_t *vf = INTER_FILTER(hpel_if_idx, my);
295 
296  if (pu->dmvr_flag) {
297  const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs));
298  const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs));
299 
300  MC_EMULATED_EDGE_DMVR(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy);
301  } else {
302  MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
303  }
304  fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w);
305  if (sb_bdof_flag)
306  fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h);
307  }
308  if (sb_bdof_flag)
309  fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
310  else if (weight_flag)
311  fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
312  else
313  fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
314 }
315 
316 static const int8_t* inter_filter_scaled(const int scale, const int is_chroma, const int is_affine)
317 {
318 #define SCALE_THRESHOLD_1 20480
319 #define SCALE_THRESHOLD_2 28672
320 
321  const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1);
322 
323  if (!is_chroma) {
324  if (!is_affine)
325  return &ff_vvc_inter_luma_filters[i + !!i][0][0]; //hpel 1 is not needed for scaled
327  }
328 
329  return &ff_vvc_inter_chroma_filters[i][0][0];
330 }
331 #define INTER_FILTER_SCALED(scale) inter_filter_scaled(scale, is_chroma, is_affine)
332 
333 #define SCALED_CHROMA_ADDIN(scale, collocated_flag) (is_chroma ? (collocated_flag ? 0 : 8 * (scale - (1 << 14))) : 0)
334 #define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) ((((off - (scaling_off << shift)) << (4 + shift)) + ref_mv) * scale + add)
335 #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))
336 #define SCALED_STEP(scale) ((scale + 8) >> 4)
337 
338 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,
339  int *x, int *y, int *dx, int *dy)
340 {
341  const VVCFrameContext *fc = lc->fc;
342  const VVCSPS *sps = fc->ps.sps;
343  const int is_chroma = !!c_idx;
344  const int hs = sps->hshift[c_idx];
345  const int vs = sps->vshift[c_idx];
346  const int left_offset = fc->ref->scaling_win.left_offset;
347  const int top_offset = fc->ref->scaling_win.top_offset;
348  const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag);
349  const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag);
350  const int refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs);
351  const int refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs);
352 
353  *x = SCALED_REF(refx_sb, left_offset, hs);
354  *y = SCALED_REF(refy_sb, top_offset, vs);
355  *dx = SCALED_STEP(refp->scale[0]);
356  *dy = SCALED_STEP(refp->scale[1]);
357 }
358 
359 static void emulated_edge_scaled(VVCLocalContext *lc, const uint8_t **src, ptrdiff_t *src_stride, int *src_height,
360  const VVCFrame *ref, const int x, const int y, const int dx, const int dy,
361  const int block_w, const int block_h, const int is_chroma)
362 {
363  const VVCFrameContext *fc = lc->fc;
364  const int x0 = SCALED_INT(x);
365  const int y0 = SCALED_INT(y);
366  const int x_end = SCALED_INT(x + block_w * dx);
367  const int y_end = SCALED_INT(y + block_h * dy);
368  const int x_last = SCALED_INT(x + (block_w - 1) * dx);
369  const int y_last = SCALED_INT(y + (block_h - 1) * dy);
370  const int src_width = x_end - x0 + (x_end == x_last);
371 
372  *src_height = y_end - y0 + (y_end == y_last);
373 
374  *src += y0 * *src_stride + (x0 * (1 << fc->ps.sps->pixel_shift));
375 
376  emulated_edge(lc, lc->edge_emu_buffer, src, src_stride, ref, x0, y0, src_width, *src_height, is_chroma);
377 }
378 
379 static void mc_scaled(VVCLocalContext *lc, int16_t *dst, const VVCRefPic *refp, const Mv *mv,
380  int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
381 {
382  const VVCFrameContext *fc = lc->fc;
383  const PredictionUnit *pu = &lc->cu->pu;
384  const uint8_t *src = refp->ref->frame->data[c_idx];
385  ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx];
386  const int is_affine = pu->inter_affine_flag;
387  const int is_chroma = !!c_idx;
388  const int idx = av_log2(block_w) - 1;
389  const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]);
390  const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]);
391  int x, y, dx, dy, src_height;
392 
393  scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy);
394  emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma);
395  fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w);
396 }
397 
398 static void mc_uni_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp,
399  const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
400 {
401  const VVCFrameContext *fc = lc->fc;
402  const PredictionUnit *pu = &lc->cu->pu;
403  const uint8_t *src = refp->ref->frame->data[c_idx];
404  ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx];
405  const int lx = mvf->pred_flag - PF_L0;
406  const Mv *mv = &mvf->mv[lx];
407  const int is_affine = pu->inter_affine_flag;
408  const int is_chroma = !!c_idx;
409  const int idx = av_log2(block_w) - 1;
410  const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]);
411  const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]);
412  int denom, wx, ox, x, y, dx, dy, src_height;
413 
414  scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy);
415  emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma);
416 
417  if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) {
418  fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height,
419  x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w);
420  } else {
421  fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height,
422  x, y, dx, dy, block_h, hf, vf, block_w);
423  }
424 }
425 
426 static void mc_bi_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
427  const VVCRefPic *refp0, const VVCRefPic *refp1, const MvField *mvf,
428  const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
429 {
430  int denom, w0, w1, o0, o1;
431  const VVCFrameContext *fc = lc->fc;
432  const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, lc->cu->pu.dmvr_flag);
433  const VVCRefPic *refps[] = { refp0, refp1 };
434  int16_t *tmp[] = { lc->tmp, lc->tmp1 };
435 
436  for (int i = L0; i <= L1; i++) {
437  const Mv *mv = mvf->mv + i;
438  const VVCRefPic *refp = refps[i];
439 
440  if (refp->is_scaled)
441  mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx);
442  else
443  mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx);
444  }
445  if (weight_flag)
446  fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
447  else
448  fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
449 }
450 
451 static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
452  const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
453  const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y)
454 {
455  const VVCFrameContext *fc = lc->fc;
456  const uint8_t *src = ref->frame->data[LUMA];
457  ptrdiff_t src_stride = ref->frame->linesize[LUMA];
458  uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET;
459  const int idx = av_log2(block_w) - 1;
460  const int lx = mvf->pred_flag - PF_L0;
461  const Mv *mv = mvf->mv + lx;
462  const int mx = mv->x & 0xf;
463  const int my = mv->y & 0xf;
466  int denom, wx, ox;
467  const int weight_flag = derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA);
468  const int is_chroma = 0;
469 
470  x_off += mv->x >> 4;
471  y_off += mv->y >> 4;
472  src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
473 
474  MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
475  if (cb_prof_flag) {
476  fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
477  fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
478  if (!weight_flag)
479  fc->vvcdsp.inter.apply_prof_uni(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y);
480  else
481  fc->vvcdsp.inter.apply_prof_uni_w(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y, denom, wx, ox);
482  } else {
483  if (!weight_flag)
484  fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w);
485  else
486  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);
487  }
488 }
489 
490 static void luma_prof(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref,
491  const Mv *mv , const int x_off, const int y_off, const int block_w, const int block_h, const int lx)
492 {
493  const VVCFrameContext *fc = lc->fc;
494  const PredictionUnit *pu = &lc->cu->pu;
495  const int mx = mv->x & 0xf;
496  const int my = mv->y & 0xf;
497  const int ox = x_off + (mv->x >> 4);
498  const int oy = y_off + (mv->y >> 4);
499  const int idx = av_log2(block_w) - 1;
500  const int is_chroma = 0;
501  uint16_t *prof_tmp = lc->tmp2 + PROF_TEMP_OFFSET;
502  ptrdiff_t src_stride = ref->frame->linesize[0];
503  const uint8_t *src = ref->frame->data[0] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
506 
507  MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
508  if (!pu->cb_prof_flag[lx]) {
509  fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
510  } else {
511  fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
512  fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
513  fc->vvcdsp.inter.apply_prof(dst, prof_tmp, pu->diff_mv_x[lx], pu->diff_mv_y[lx]);
514  }
515 }
516 
517 static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
518  const VVCRefPic *ref0, const VVCRefPic *ref1, const MvField *mvf, const int x_off, const int y_off,
519  const int block_w, const int block_h)
520 {
521  const VVCFrameContext *fc = lc->fc;
522  const VVCRefPic *refps[] = { ref0, ref1 };
523  int16_t *tmp[] = { lc->tmp, lc->tmp1 };
524  int denom, w0, w1, o0, o1;
525  const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, LUMA, 0);
526 
527  for (int i = L0; i <= L1; i++) {
528  const VVCRefPic *refp = refps[i];
529  const Mv *mv = mvf->mv + i;
530 
531  if (refp->is_scaled)
532  mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, LUMA);
533  else
534  luma_prof(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, i);
535  }
536 
537  if (weight_flag)
538  fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
539  else
540  fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
541 }
542 
543 static int pred_get_refs(const VVCLocalContext *lc, VVCRefPic *refp[2], const MvField *mv)
544 {
545  RefPicList *rpl = lc->sc->rpl;
546 
547  for (int mask = PF_L0; mask <= PF_L1; mask++) {
548  if (mv->pred_flag & mask) {
549  const int lx = mask - PF_L0;
550  refp[lx] = rpl[lx].refs + mv->ref_idx[lx];
551  if (!refp[lx]->ref)
552  return AVERROR_INVALIDDATA;
553  }
554  }
555  return 0;
556 }
557 
558 #define POS(c_idx, x, y) \
559  &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
560  (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
561 
563 {
564  const VVCFrameContext *fc = lc->fc;
565  const CodingUnit *cu = lc->cu;
566  const PredictionUnit *pu = &cu->pu;
567 
568  const uint8_t angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx];
569  const uint8_t weights_idx = ff_vvc_gpm_angle_to_weights_idx[angle_idx];
570  const int w = av_log2(cu->cb_width) - 3;
571  const int h = av_log2(cu->cb_height) - 3;
572  const uint8_t off_x = ff_vvc_gpm_weights_offset_x[pu->gpm_partition_idx][h][w];
573  const uint8_t off_y = ff_vvc_gpm_weights_offset_y[pu->gpm_partition_idx][h][w];
574  const uint8_t mirror_type = ff_vvc_gpm_angle_to_mirror[angle_idx];
575  const uint8_t *weights;
576 
577  const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1;
578 
579  int16_t *tmp[2] = {lc->tmp, lc->tmp1};
580 
581  for (int c_idx = 0; c_idx < c_end; c_idx++) {
582  const int hs = fc->ps.sps->hshift[c_idx];
583  const int vs = fc->ps.sps->vshift[c_idx];
584  const int x = lc->cu->x0 >> hs;
585  const int y = lc->cu->y0 >> vs;
586  const int width = cu->cb_width >> hs;
587  const int height = cu->cb_height >> vs;
588  uint8_t *dst = POS(c_idx, lc->cu->x0, lc->cu->y0);
589  ptrdiff_t dst_stride = fc->frame->linesize[c_idx];
590 
591  int step_x = 1 << hs;
592  int step_y = VVC_GPM_WEIGHT_SIZE << vs;
593  if (!mirror_type) {
594  weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + off_x];
595  } else if (mirror_type == 1) {
596  step_x = -step_x;
597  weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + VVC_GPM_WEIGHT_SIZE - 1- off_x];
598  } else {
599  step_y = -step_y;
600  weights = &ff_vvc_gpm_weights[weights_idx][(VVC_GPM_WEIGHT_SIZE - 1 - off_y) * VVC_GPM_WEIGHT_SIZE + off_x];
601  }
602 
603  for (int i = 0; i < 2; i++) {
604  const MvField *mv = pu->gpm_mv + i;
605  const int lx = mv->pred_flag - PF_L0;
606  VVCRefPic *refp = lc->sc->rpl[lx].refs + mv->ref_idx[lx];
607  if (!refp->ref)
608  return;
609  if (refp->is_scaled)
610  mc_scaled(lc, tmp[i], refp, mv->mv + lx, x, y, width, height, c_idx);
611  else
612  mc(lc, tmp[i], refp->ref, mv->mv + lx, x, y, width, height, c_idx);
613  }
614  fc->vvcdsp.inter.put_gpm(dst, dst_stride, width, height, tmp[0], tmp[1], weights, step_x, step_y);
615  }
616  return;
617 }
618 
619 static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0,
620  const int width, const int height)
621 {
622  const VVCFrameContext *fc = lc->fc;
623  const VVCSPS *sps = fc->ps.sps;
624  const int x0b = av_mod_uintp2(x0, sps->ctb_log2_size_y);
625  const int y0b = av_mod_uintp2(y0, sps->ctb_log2_size_y);
626  const int available_l = lc->ctb_left_flag || x0b;
627  const int available_u = lc->ctb_up_flag || y0b;
628  const int min_pu_width = fc->ps.pps->min_pu_width;
629 
630  int w = 1;
631 
632  if (available_u &&fc->tab.mvf[((y0 - 1) >> MIN_PU_LOG2) * min_pu_width + ((x0 - 1 + width)>> MIN_PU_LOG2)].pred_flag == PF_INTRA)
633  w++;
634 
635  if (available_l && fc->tab.mvf[((y0 - 1 + height)>> MIN_PU_LOG2) * min_pu_width + ((x0 - 1) >> MIN_PU_LOG2)].pred_flag == PF_INTRA)
636  w++;
637 
638  return w;
639 }
640 
641 static void pred_regular(VVCLocalContext *lc, const MvField *mvf, const MvField *orig_mvf,
642  const int x0, const int y0, const int sbw, const int sbh, const int sb_bdof_flag, const int c_start)
643 {
644  const VVCFrameContext *fc = lc->fc;
645  const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? CR : LUMA;
646  VVCRefPic *refp[2];
647 
648  if (pred_get_refs(lc, refp, mvf) < 0)
649  return;
650 
651  for (int c_idx = c_start; c_idx <= c_end; c_idx++) {
652  uint8_t *dst = POS(c_idx, x0, y0);
653  const ptrdiff_t dst_stride = fc->frame->linesize[c_idx];
654  const int hs = fc->ps.sps->hshift[c_idx];
655  const int vs = fc->ps.sps->vshift[c_idx];
656  const int x = x0 >> hs;
657  const int y = y0 >> vs;
658  const int w = sbw >> hs;
659  const int h = sbh >> vs;
660  const int is_luma = !c_idx;
661  const int do_ciip = lc->cu->ciip_flag && (is_luma || (w > 2));
662  uint8_t *inter = do_ciip ? (uint8_t *)lc->ciip_tmp : dst;
663  const ptrdiff_t inter_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst_stride;
664  const int do_bdof = is_luma && sb_bdof_flag;
665 
666  if (mvf->pred_flag != PF_BI) {
667  const int lx = mvf->pred_flag - PF_L0;
668 
669  if (refp[lx]->is_scaled) {
670  mc_uni_scaled(lc, inter, inter_stride, refp[lx], mvf,
671  x, y, w, h, c_idx);
672  } else {
673  mc_uni(lc, inter, inter_stride, refp[lx]->ref, mvf,
674  x, y, w, h, c_idx);
675  }
676  } else {
677  if (refp[L0]->is_scaled || refp[L1]->is_scaled) {
678  mc_bi_scaled(lc, inter, inter_stride, refp[L0], refp[L1], mvf,
679  x, y, w, h, c_idx);
680  } else {
681  mc_bi(lc, inter, inter_stride, refp[L0]->ref, refp[L1]->ref, mvf, orig_mvf,
682  x, y, w, h, c_idx, do_bdof);
683  }
684  }
685  if (do_ciip) {
686  const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
687  fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, c_idx);
688  if (!c_idx && lc->sc->sh.r->sh_lmcs_used_flag)
689  fc->vvcdsp.lmcs.filter(inter, inter_stride, w, h, &fc->ps.lmcs.fwd_lut);
690  fc->vvcdsp.inter.put_ciip(dst, dst_stride, w, h, inter, inter_stride, intra_weight);
691  }
692  }
693 }
694 
695 // 8.5.3.5 Parametric motion vector refinement process
696 static int parametric_mv_refine(const int *sad, const int stride)
697 {
698  const int sad_minus = sad[-stride];
699  const int sad_center = sad[0];
700  const int sad_plus = sad[stride];
701  int dmvc;
702  int denom = (( sad_minus + sad_plus) - (sad_center << 1 ) ) << 3;
703  if (!denom)
704  dmvc = 0;
705  else {
706  if (sad_minus == sad_center)
707  dmvc = -8;
708  else if (sad_plus == sad_center)
709  dmvc = 8;
710  else {
711  int num = ( sad_minus - sad_plus ) * (1 << 4);
712  int sign_num = 0;
713  int quotient = 0;
714  int counter = 3;
715  if (num < 0 ) {
716  num = - num;
717  sign_num = 1;
718  }
719  while (counter > 0) {
720  counter = counter - 1;
721  quotient = quotient << 1;
722  if ( num >= denom ) {
723  num = num - denom;
724  quotient = quotient + 1;
725  }
726  denom = (denom >> 1);
727  }
728  if (sign_num == 1 )
729  dmvc = -quotient;
730  else
731  dmvc = quotient;
732  }
733  }
734  return dmvc;
735 }
736 
737 #define SAD_ARRAY_SIZE 5
738 //8.5.3 Decoder-side motion vector refinement process
739 static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag,
740  const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h)
741 {
742  const VVCFrameContext *fc = lc->fc;
743  const int sr_range = 2;
744  const AVFrame *ref[] = { ref0, ref1 };
745  int16_t *tmp[] = { lc->tmp, lc->tmp1 };
746  int sad[SAD_ARRAY_SIZE][SAD_ARRAY_SIZE];
747  int min_dx, min_dy, min_sad, dx, dy;
748 
749  *orig_mv = *mvf;
750  min_dx = min_dy = dx = dy = 2;
751 
752  for (int i = L0; i <= L1; i++) {
753  const int pred_w = block_w + 2 * sr_range;
754  const int pred_h = block_h + 2 * sr_range;
755  const Mv *mv = mvf->mv + i;
756  const int mx = mv->x & 0xf;
757  const int my = mv->y & 0xf;
758  const int ox = x_off + (mv->x >> 4) - sr_range;
759  const int oy = y_off + (mv->y >> 4) - sr_range;
760  ptrdiff_t src_stride = ref[i]->linesize[LUMA];
761  const uint8_t *src = ref[i]->data[LUMA] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
762  MC_EMULATED_EDGE_BILINEAR(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
763  fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w);
764  }
765 
766  min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h);
767  min_sad -= min_sad >> 2;
768  sad[dy][dx] = min_sad;
769 
770  if (min_sad >= block_w * block_h) {
771  int dmv[2];
772  // 8.5.3.4 Array entry selection process
773  for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
774  for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
775  if (dx != sr_range || dy != sr_range) {
776  sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, dy, block_w, block_h);
777  if (sad[dy][dx] < min_sad) {
778  min_sad = sad[dy][dx];
779  min_dx = dx;
780  min_dy = dy;
781  }
782  }
783  }
784  }
785  dmv[0] = (min_dx - sr_range) * (1 << 4);
786  dmv[1] = (min_dy - sr_range) * (1 << 4);
787  if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) {
788  dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1);
789  dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE);
790  }
791 
792  for (int i = L0; i <= L1; i++) {
793  Mv *mv = mvf->mv + i;
794  mv->x += (1 - 2 * i) * dmv[0];
795  mv->y += (1 - 2 * i) * dmv[1];
797  }
798  }
799  if (min_sad < 2 * block_w * block_h) {
800  *sb_bdof_flag = 0;
801  }
802 }
803 
804 static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0,
805  const int width, const int height, const MvField *mvf)
806 
807 {
808  const VVCPPS *pps = fc->ps.pps;
809 
810  for (int y = y0; y < y0 + height; y += MIN_PU_SIZE) {
811  for (int x = x0; x < x0 + width; x += MIN_PU_SIZE) {
812  const int idx = pps->min_pu_width * (y >> MIN_PU_LOG2) + (x >> MIN_PU_LOG2);
813  fc->ref->tab_dmvr_mvf[idx] = *mvf;
814  }
815  }
816 }
817 
818 static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag,
819  const int x0, const int y0, const int sbw, const int sbh)
820 {
821  VVCFrameContext *fc = lc->fc;
822  const PredictionUnit *pu = &lc->cu->pu;
823 
824  *orig_mv = *mv = *ff_vvc_get_mvf(fc, x0, y0);
825  if (pu->bdof_flag)
826  *sb_bdof_flag = 1;
827  if (pu->dmvr_flag) {
828  VVCRefPic *refp[2];
829  if (pred_get_refs(lc, refp, mv) < 0)
830  return;
831  dmvr_mv_refine(lc, mv, orig_mv, sb_bdof_flag, refp[L0]->ref->frame, refp[L1]->ref->frame, x0, y0, sbw, sbh);
832  set_dmvr_info(fc, x0, y0, sbw, sbh, mv);
833  }
834 }
835 
836 static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip)
837 {
838  const CodingUnit *cu = lc->cu;
839  PredictionUnit *pu = &lc->cu->pu;
840  const MotionInfo *mi = &pu->mi;
841  MvField mv, orig_mv;
842  int sbw, sbh, sb_bdof_flag = 0;
843 
844  if (cu->ciip_flag && skip_ciip)
845  return;
846 
847  sbw = cu->cb_width / mi->num_sb_x;
848  sbh = cu->cb_height / mi->num_sb_y;
849 
850  for (int sby = 0; sby < mi->num_sb_y; sby++) {
851  for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
852  const int x0 = cu->x0 + sbx * sbw;
853  const int y0 = cu->y0 + sby * sbh;
854 
855  if (cu->ciip_flag)
856  ff_vvc_set_neighbour_available(lc, x0, y0, sbw, sbh);
857 
858  derive_sb_mv(lc, &mv, &orig_mv, &sb_bdof_flag, x0, y0, sbw, sbh);
859  pred_regular(lc, &mv, &orig_mv, x0, y0, sbw, sbh, sb_bdof_flag, LUMA);
860  }
861  }
862 }
863 
864 static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv,
865  const int x0, const int y0, const int sbw, const int sbh)
866 {
867  const int hs = fc->ps.sps->hshift[1];
868  const int vs = fc->ps.sps->vshift[1];
869  const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh);
870  *mvc = *mv;
871 
872  // Due to different pred_flag, one of the motion vectors may have an invalid value.
873  // Cast them to an unsigned type to avoid undefined behavior.
874  mvc->mv[0].x += (unsigned int)mv2->mv[0].x;
875  mvc->mv[0].y += (unsigned int)mv2->mv[0].y;
876  mvc->mv[1].x += (unsigned int)mv2->mv[1].x;
877  mvc->mv[1].y += (unsigned int)mv2->mv[1].y;
878  ff_vvc_round_mv(mvc->mv + 0, 0, 1);
879  ff_vvc_round_mv(mvc->mv + 1, 0, 1);
880 }
881 
883 {
884  const VVCFrameContext *fc = lc->fc;
885  const CodingUnit *cu = lc->cu;
886  const PredictionUnit *pu = &cu->pu;
887  const MotionInfo *mi = &pu->mi;
888  const int x0 = cu->x0;
889  const int y0 = cu->y0;
890  const int sbw = cu->cb_width / mi->num_sb_x;
891  const int sbh = cu->cb_height / mi->num_sb_y;
892  const int hs = fc->ps.sps->hshift[1];
893  const int vs = fc->ps.sps->vshift[1];
894  const int dst_stride = fc->frame->linesize[LUMA];
895 
896  for (int sby = 0; sby < mi->num_sb_y; sby++) {
897  for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
898  const int x = x0 + sbx * sbw;
899  const int y = y0 + sby * sbh;
900 
901  uint8_t *dst0 = POS(0, x, y);
902  const MvField *mv = ff_vvc_get_mvf(fc, x, y);
903  VVCRefPic *refp[2];
904 
905  if (pred_get_refs(lc, refp, mv) < 0)
906  return;
907 
908  if (mi->pred_flag != PF_BI) {
909  const int lx = mi->pred_flag - PF_L0;
910  if (refp[lx]->is_scaled) {
911  mc_uni_scaled(lc, dst0, dst_stride, refp[lx], mv, x, y, sbw, sbh, LUMA);
912  } else {
913  luma_prof_uni(lc, dst0, dst_stride, refp[lx]->ref,
914  mv, x, y, sbw, sbh, pu->cb_prof_flag[lx],
915  pu->diff_mv_x[lx], pu->diff_mv_y[lx]);
916  }
917  } else {
918  luma_prof_bi(lc, dst0, dst_stride, refp[L0], refp[L1], mv, x, y, sbw, sbh);
919  }
920  if (fc->ps.sps->r->sps_chroma_format_idc) {
921  if (!av_mod_uintp2(sby, vs) && !av_mod_uintp2(sbx, hs)) {
922  MvField mvc;
923 
924  derive_affine_mvc(&mvc, fc, mv, x, y, sbw, sbh);
925  pred_regular(lc, &mvc, NULL, x, y, sbw << hs, sbh << vs, 0, CB);
926  }
927  }
928 
929  }
930  }
931 }
932 
934 {
935  const VVCFrameContext *fc = lc->fc;
936  const CodingUnit *cu = lc->cu;
937  const PredictionUnit *pu = &cu->pu;
938 
939  if (pu->merge_gpm_flag)
940  pred_gpm_blk(lc);
941  else if (pu->inter_affine_flag)
942  pred_affine_blk(lc);
943  else
944  pred_regular_blk(lc, 1); //intra block is not ready yet, skip ciip
945 
946  if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
947  uint8_t* dst0 = POS(0, cu->x0, cu->y0);
948  fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
949  }
950 }
951 
952 static int has_inter_luma(const CodingUnit *cu)
953 {
954  return (cu->pred_mode == MODE_INTER || cu->pred_mode == MODE_SKIP) && cu->tree_type != DUAL_TREE_CHROMA;
955 }
956 
957 int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs)
958 {
959  const VVCFrameContext *fc = lc->fc;
960  const CTU *ctu = fc->tab.ctus + rs;
961  CodingUnit *cu = ctu->cus;
962 
963  while (cu) {
964  lc->cu = cu;
965  if (has_inter_luma(cu))
966  predict_inter(lc);
967  cu = cu->next;
968  }
969 
970  return 0;
971 }
972 
974 {
975  av_assert0(lc->cu->ciip_flag);
976 
977  //todo: refact out ciip from pred_regular_blk
978  pred_regular_blk(lc, 0);
979 }
980 
981 #undef POS
set_dmvr_info
static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0, const int width, const int height, const MvField *mvf)
Definition: inter.c:804
ff_vvc_inter_luma_filters
const int8_t ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPES][VVC_INTER_LUMA_FACTS][VVC_INTER_LUMA_TAPS]
Definition: data.c:1735
CB
#define CB
Definition: hevc_filter.c:32
VVCSPS
Definition: ps.h:58
L1
F H1 F F H1 F F F F H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F|||||||||F H1 F|||||||||F H1 Funavailable fullpel samples(outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically, horizontally or diagonally adjacent halfpel points shall be interpolatedlinearly with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F--> O q O<--h1-> O q O<--F v \/v \/v O O O O O O O|/|\|q q q q q|/|\|O O O O O O O ^/\ ^/\ ^ h2--> O q O<--h3-> O q O<--h2 v \/v \/v O O O O O O O|\|/|q q q q q|\|/|O O O O O O O ^/\ ^/\ ^ F--> O q O<--h1-> O q O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0;y< height;y++){ for(x=0;x< width;x++){ sample[y][x]+=median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]);}}sample[-1][ *]=sample[ *][-1]=0;width, height here are the width and height of the LL0 subband not of the finalvideoDequantization:===============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and an integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT(inverse discrete wavelet transform) --------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0|||||||||||||---+---|HL1||L0|H0|HL1||LL1|HL1|||||LH0|HH0|||||||||||||-------+-------|-> L1 H1 LH1 HH1 LH1 HH1 LH1 HH1 L1
Definition: snow.txt:554
VVCPPS
Definition: ps.h:92
VVCFrame::pps
const VVCPPS * pps
RefStruct reference.
Definition: dec.h:75
SCALE_THRESHOLD_1
#define SCALE_THRESHOLD_1
luma_prof
static void luma_prof(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv, const int x_off, const int y_off, const int block_w, const int block_h, const int lx)
Definition: inter.c:490
VVC_INTER_LUMA_FILTER_TYPE_AFFINE
#define VVC_INTER_LUMA_FILTER_TYPE_AFFINE
Definition: data.h:46
MotionInfo
Definition: ctu.h:239
ff_vvc_gpm_weights
const uint8_t ff_vvc_gpm_weights[6][VVC_GPM_WEIGHT_SIZE *VVC_GPM_WEIGHT_SIZE]
Definition: data.c:2880
emulated_edge
static int emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame, int x_off, int y_off, const int block_w, const int block_h, const int is_chroma)
Definition: inter.c:47
CodingUnit
Definition: hevcdec.h:282
BILINEAR_EXTRA
#define BILINEAR_EXTRA
Definition: ctu.h:60
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
PredictionUnit::gpm_partition_idx
uint8_t gpm_partition_idx
Definition: ctu.h:261
VVCLocalContext::tmp
int16_t tmp[MAX_PB_SIZE *MAX_PB_SIZE]
Definition: ctu.h:381
av_mod_uintp2
#define av_mod_uintp2
Definition: common.h:126
ff_vvc_predict_inter
int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs)
Loop entire CTU to predict all inter coding blocks.
Definition: inter.c:957
VVCLocalContext::ciip_tmp
uint8_t ciip_tmp[MAX_PB_SIZE *MAX_PB_SIZE *2]
Definition: ctu.h:384
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
VVCRefPic
Definition: dec.h:45
w
uint8_t w
Definition: llviddspenc.c:38
VVCLocalContext::sc
SliceContext * sc
Definition: ctu.h:432
CHROMA_EXTRA_BEFORE
#define CHROMA_EXTRA_BEFORE
Definition: h2656_inter_template.c:24
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:297
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:232
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:464
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
RefPicList
Definition: hevcdec.h:189
derive_sb_mv
static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag, const int x0, const int y0, const int sbw, const int sbh)
Definition: inter.c:818
emulated_edge_dmvr
static void emulated_edge_dmvr(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, int x_sb, int y_sb, int x_off, int y_off, const int block_w, const int block_h, const int is_chroma)
Definition: inter.c:80
PF_INTRA
@ PF_INTRA
Definition: hevcdec.h:113
INTER_FILTER
#define INTER_FILTER(t, frac)
Definition: inter.c:205
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:395
VVCRefPic::ref
struct VVCFrame * ref
Definition: dec.h:46
MODE_SKIP
@ MODE_SKIP
Definition: hevcdec.h:103
ff_vvc_clip_mv
void ff_vvc_clip_mv(Mv *mv)
Definition: mvs.c:1863
MIN_PU_LOG2
#define MIN_PU_LOG2
Definition: dec.h:40
MC_EMULATED_EDGE_DMVR
#define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off)
Definition: inter.c:148
PredictionUnit::gpm_mv
MvField gpm_mv[2]
Definition: ctu.h:262
IS_P
#define IS_P(rsh)
Definition: ps.h:39
VVCLocalContext::fc
VVCFrameContext * fc
Definition: ctu.h:433
VVC_GPM_WEIGHT_SIZE
#define VVC_GPM_WEIGHT_SIZE
Definition: data.h:68
VVCSH::pwt
PredWeightTable pwt
Definition: ps.h:240
PredictionUnit
Definition: hevcdec.h:315
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:101
VVCLocalContext::tmp1
int16_t tmp1[MAX_PB_SIZE *MAX_PB_SIZE]
Definition: ctu.h:382
derive_weight_uni
static int derive_weight_uni(int *denom, int *wx, int *ox, const VVCLocalContext *lc, const MvField *mvf, const int c_idx)
Definition: inter.c:155
SCALED_INT
#define SCALED_INT(pos)
Definition: ctu.h:62
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:111
SCALED_REF
#define SCALED_REF(ref_sb, offset, shift)
Definition: inter.c:335
ff_vvc_get_mvf
MvField * ff_vvc_get_mvf(const VVCFrameContext *fc, const int x0, const int y0)
Definition: mvs.c:1923
emulated_edge_bilinear
static void emulated_edge_bilinear(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, int x_off, int y_off, const int block_w, const int block_h)
Definition: inter.c:118
bcw_w_lut
static const int bcw_w_lut[]
Definition: inter.c:31
CodingUnit::cb_width
int cb_width
Definition: ctu.h:281
INTER_FILTER_SCALED
#define INTER_FILTER_SCALED(scale)
Definition: inter.c:331
CodingUnit::pu
PredictionUnit pu
Definition: ctu.h:326
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:56
mask
static const uint16_t mask[17]
Definition: lzw.c:38
PROF_TEMP_OFFSET
#define PROF_TEMP_OFFSET
Definition: inter.c:30
SCALED_CHROMA_ADDIN
#define SCALED_CHROMA_ADDIN(scale, collocated_flag)
Definition: inter.c:333
width
#define width
mi
#define mi
Definition: vf_colormatrix.c:106
ff_vvc_gpm_weights_offset_x
const uint8_t ff_vvc_gpm_weights_offset_x[VVC_GPM_NUM_PARTITION][4][4]
Definition: data.c:2106
LUMA_EXTRA_AFTER
#define LUMA_EXTRA_AFTER
Definition: ctu.h:56
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ff_vvc_gpm_angle_to_weights_idx
const uint8_t ff_vvc_gpm_angle_to_weights_idx[VVC_GPM_NUM_ANGLES]
Definition: data.c:2100
VVCSH
Definition: ps.h:231
VVCLocalContext::edge_emu_buffer
uint8_t edge_emu_buffer[EDGE_EMU_BUFFER_STRIDE *EDGE_EMU_BUFFER_STRIDE *2]
Definition: ctu.h:380
PredWeightTable
Definition: ps.h:137
CodingUnit::tree_type
VVCTreeType tree_type
Definition: ctu.h:278
LUMA_EXTRA
#define LUMA_EXTRA
Definition: h2656_inter_template.c:27
PredictionUnit::bdof_flag
uint8_t bdof_flag
Definition: ctu.h:270
has_inter_luma
static int has_inter_luma(const CodingUnit *cu)
Definition: inter.c:952
ff_vvc_gpm_angle_idx
const uint8_t ff_vvc_gpm_angle_idx[VVC_GPM_NUM_PARTITION]
Definition: data.c:2077
SCALE_THRESHOLD_2
#define SCALE_THRESHOLD_2
H266RawSliceHeader::sh_lmcs_used_flag
uint8_t sh_lmcs_used_flag
Definition: cbs_h266.h:792
derive_weight
static int derive_weight(int *denom, int *w0, int *w1, int *o0, int *o1, const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag)
Definition: inter.c:175
CTU
Definition: ctu.h:331
inter.h
SAD_ARRAY_SIZE
#define SAD_ARRAY_SIZE
Definition: inter.c:737
NULL
#define NULL
Definition: coverity.c:32
mc_scaled
static void mc_scaled(VVCLocalContext *lc, int16_t *dst, const VVCRefPic *refp, const Mv *mv, int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
Definition: inter.c:379
SCALED_STEP
#define SCALED_STEP(scale)
Definition: inter.c:336
derive_affine_mvc
static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv, const int x0, const int y0, const int sbw, const int sbh)
Definition: inter.c:864
VVCLocalContext
Definition: ctu.h:371
pred_h
static void FUNC() pred_h(uint8_t *_src, const uint8_t *_left, const int w, const int h, const ptrdiff_t stride)
Definition: intra_template.c:877
H266RawSliceHeader::curr_subpic_idx
uint16_t curr_subpic_idx
CurrSubpicIdx.
Definition: cbs_h266.h:835
mc_bi_scaled
static void mc_bi_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp0, const VVCRefPic *refp1, const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
Definition: inter.c:426
L0
#define L0
Definition: hevcdec.h:57
scaled_ref_pos_and_step
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, int *x, int *y, int *dx, int *dy)
Definition: inter.c:338
MC_EMULATED_EDGE
#define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off)
Definition: inter.c:145
LUMA_EXTRA_BEFORE
#define LUMA_EXTRA_BEFORE
Definition: h2656_inter_template.c:26
dmvr_mv_refine
static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag, const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h)
Definition: inter.c:739
VVCRefPic::is_scaled
int is_scaled
RprConstraintsActiveFlag.
Definition: dec.h:51
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:296
PF_BI
@ PF_BI
Definition: hevcdec.h:116
predict_inter
static void predict_inter(VVCLocalContext *lc)
Definition: inter.c:933
IS_B
#define IS_B(rsh)
Definition: ps.h:40
ff_vvc_inter_chroma_filters
const int8_t ff_vvc_inter_chroma_filters[VVC_INTER_CHROMA_FILTER_TYPES][VVC_INTER_CHROMA_FACTS][VVC_INTER_CHROMA_TAPS]
Definition: data.c:1877
MIN_PU_SIZE
#define MIN_PU_SIZE
Definition: ctu.h:40
pred_affine_blk
static void pred_affine_blk(VVCLocalContext *lc)
Definition: inter.c:882
mvs.h
MotionInfo::hpel_if_idx
uint8_t hpel_if_idx
hpelIfIdx
Definition: ctu.h:242
PredictionUnit::merge_gpm_flag
uint8_t merge_gpm_flag
Definition: ctu.h:260
PredictionUnit::cb_prof_flag
int cb_prof_flag[2]
Definition: ctu.h:274
CR
#define CR
Definition: hevc_filter.c:33
MvField
Definition: hevcdec.h:300
refs.h
frame.h
pred_gpm_blk
static void pred_gpm_blk(VVCLocalContext *lc)
Definition: inter.c:562
PF_L1
@ PF_L1
Definition: hevcdec.h:115
AFFINE_MIN_BLOCK_SIZE
#define AFFINE_MIN_BLOCK_SIZE
Definition: ctu.h:66
ff_vvc_round_mv
void ff_vvc_round_mv(Mv *mv, const int lshift, const int rshift)
Definition: mvs.c:1851
VVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: ctu.h:373
pred_regular
static void pred_regular(VVCLocalContext *lc, const MvField *mvf, const MvField *orig_mvf, const int x0, const int y0, const int sbw, const int sbh, const int sb_bdof_flag, const int c_start)
Definition: inter.c:641
PredictionUnit::diff_mv_x
int16_t diff_mv_x[2][AFFINE_MIN_BLOCK_SIZE *AFFINE_MIN_BLOCK_SIZE]
diffMvLX
Definition: ctu.h:272
VVCFrame
Definition: dec.h:71
height
#define height
ff_vvc_gpm_weights_offset_y
const uint8_t ff_vvc_gpm_weights_offset_y[VVC_GPM_NUM_PARTITION][4][4]
Definition: data.c:2493
CHROMA_EXTRA_AFTER
#define CHROMA_EXTRA_AFTER
Definition: ctu.h:53
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_vvc_predict_ciip
void ff_vvc_predict_ciip(VVCLocalContext *lc)
CIIP(Combined Inter-Intra Prediction) for a coding block.
Definition: inter.c:973
MC_EMULATED_EDGE_BILINEAR
#define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off)
Definition: inter.c:151
MvField::pred_flag
int8_t pred_flag
Definition: hevcdec.h:303
emulated_edge_scaled
static void emulated_edge_scaled(VVCLocalContext *lc, const uint8_t **src, ptrdiff_t *src_stride, int *src_height, const VVCFrame *ref, const int x, const int y, const int dx, const int dy, const int block_w, const int block_h, const int is_chroma)
Definition: inter.c:359
PredictionUnit::mi
MotionInfo mi
Definition: ctu.h:266
parametric_mv_refine
static int parametric_mv_refine(const int *sad, const int stride)
Definition: inter.c:696
mc_bi
static void mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCFrame *ref0, const VVCFrame *ref1, const MvField *mvf, const MvField *orig_mv, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx, const int sb_bdof_flag)
Definition: inter.c:267
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
pred_get_refs
static int pred_get_refs(const VVCLocalContext *lc, VVCRefPic *refp[2], const MvField *mv)
Definition: inter.c:543
MAX_PB_SIZE
#define MAX_PB_SIZE
Definition: hevcdsp.h:32
weights
static const int weights[]
Definition: hevc_pel.c:32
mc_uni_scaled
static void mc_uni_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp, const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx)
Definition: inter.c:398
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
PF_L0
@ PF_L0
Definition: hevcdec.h:114
EDGE_EMU_BUFFER_STRIDE
#define EDGE_EMU_BUFFER_STRIDE
Definition: hevcdec.h:67
POS
#define POS(c_idx, x, y)
Definition: inter.c:558
CodingUnit::x0
int x0
Definition: ctu.h:279
ff_vvc_gpm_angle_to_mirror
const uint8_t ff_vvc_gpm_angle_to_mirror[VVC_GPM_NUM_ANGLES]
Definition: data.c:2095
subpic_width_height
static void subpic_width_height(int *pic_width, int *pic_height, const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_chroma)
Definition: inter.c:40
VVCLocalContext::cu
CodingUnit * cu
Definition: ctu.h:416
stride
#define stride
Definition: h264pred_template.c:537
CHROMA_EXTRA
#define CHROMA_EXTRA
Definition: h2656_inter_template.c:25
PredictionUnit::dmvr_flag
uint8_t dmvr_flag
Definition: ctu.h:269
data.h
inter_filter_scaled
static const int8_t * inter_filter_scaled(const int scale, const int is_chroma, const int is_affine)
Definition: inter.c:316
VVCFrame::frame
struct AVFrame * frame
Definition: dec.h:72
subpic_offset
static void subpic_offset(int *x_off, int *y_off, const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_chroma)
Definition: inter.c:33
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
PredictionUnit::inter_affine_flag
uint8_t inter_affine_flag
Definition: ctu.h:255
CodingUnit::cb_height
int cb_height
Definition: ctu.h:282
BILINEAR_EXTRA_AFTER
#define BILINEAR_EXTRA_AFTER
Definition: ctu.h:59
ff_vvc_set_neighbour_available
void ff_vvc_set_neighbour_available(VVCLocalContext *lc, const int x0, const int y0, const int w, const int h)
Definition: ctu.c:2507
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: ctu.h:167
ciip_derive_intra_weight
static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0, const int width, const int height)
Definition: inter.c:619
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:286
VVCLocalContext::tmp2
int16_t tmp2[MAX_PB_SIZE *MAX_PB_SIZE]
Definition: ctu.h:383
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
BILINEAR_EXTRA_BEFORE
#define BILINEAR_EXTRA_BEFORE
Definition: ctu.h:58
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
PredictionUnit::diff_mv_y
int16_t diff_mv_y[2][AFFINE_MIN_BLOCK_SIZE *AFFINE_MIN_BLOCK_SIZE]
diffMvLX
Definition: ctu.h:273
CodingUnit::next
struct CodingUnit * next
RefStruct reference.
Definition: ctu.h:328
MvField::mv
Mv mv[2]
mvL0, vvL1
Definition: hevcdec.h:301
Mv
Definition: hevcdec.h:295
MvField::ref_idx
int8_t ref_idx[2]
refIdxL0, refIdxL1
Definition: hevcdec.h:302
CTU::cus
CodingUnit * cus
Definition: ctu.h:332
pred_regular_blk
static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip)
Definition: inter.c:836
luma_prof_bi
static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *ref0, const VVCRefPic *ref1, const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h)
Definition: inter.c:517
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
SliceContext::sh
VVCSH sh
Definition: dec.h:108
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
SCALED_REF_SB
#define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift)
Definition: inter.c:334
VVCFrameContext
Definition: dec.h:115
MvField::bcw_idx
uint8_t bcw_idx
bcwIdx
Definition: ctu.h:202
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:419
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2038
int
int
Definition: ffmpeg_filter.c:424
CodingUnit::ciip_flag
uint8_t ciip_flag
Definition: ctu.h:302
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mc_uni
static void mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
Definition: inter.c:232
VVCFrame::sps
const VVCSPS * sps
RefStruct reference.
Definition: dec.h:74
LUMA
#define LUMA
Definition: hevc_filter.c:31
VVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: ctu.h:372
luma_prof_uni
static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y)
Definition: inter.c:451
VVCRefPic::scale
int scale[2]
RefPicScale[].
Definition: dec.h:52
CodingUnit::y0
int y0
Definition: ctu.h:280
mc
static void mc(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv, int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
Definition: inter.c:207