/* * VVC inter prediction * * Copyright (C) 2022 Nuo Mi * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include "libavutil/frame.h" #include "data.h"#include "inter.h"#include "mvs.h"#include "refs.h" // +1 is enough, + 32 for asm alignment#define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32)static const int bcw_w_lut[] = {4, 5, 3, 10, -2}; static void subpic_get_rect(VVCRect *r, const VVCFrame *src_frame, const int subpic_idx, const int is_chroma){ const VVCSPS *sps = src_frame->sps; const VVCPPS *pps = src_frame->pps; const int hs = sps->hshift[is_chroma]; const int vs = sps->vshift[is_chroma]; r->l = pps->subpic_x[subpic_idx] >> hs; r->t = pps->subpic_y[subpic_idx] >> vs; r->r = r->l + (pps->subpic_width[subpic_idx] >> hs); r->b = r->t + (pps->subpic_height[subpic_idx] >> vs);} // clip to subblock and subpicture process in 8.5.6.3.2 Luma sample interpolation filtering processstatic 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){ const int l = dmvr_clip ? FFMIN(FFMAX(subpic->l, sb->l), subpic->r - 1) : subpic->l; const int t = dmvr_clip ? FFMIN(FFMAX(subpic->t, sb->t), subpic->b - 1) : subpic->t; const int r = dmvr_clip ? FFMAX(FFMIN(subpic->r, sb->r), subpic->l + 1) : subpic->r; const int b = dmvr_clip ? FFMAX(FFMIN(subpic->b, sb->b), subpic->t + 1) : subpic->b; *x_off -= l; *y_off -= t; *pic_width = r - l; *pic_height = b - t;} static void emulated_edge_no_wrap(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, const int extra_before, const int extra_after, const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip){ const VVCFrameContext *fc = lc->fc; const int extra = extra_before + extra_after; int pic_width, pic_height; *src += y_off * *src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, sb, dmvr_clip); if (dmvr_clip || x_off < extra_before || y_off < extra_before || x_off >= pic_width - block_w - extra_after || y_off >= pic_height - block_h - extra_after) { const int ps = fc->ps.sps->pixel_shift; const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps; const int offset = extra_before * *src_stride + (extra_before << ps); const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps); fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before, pic_width, pic_height); *src = dst + buf_offset; *src_stride = edge_emu_stride; }} static void emulated_half(const VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride, const int ps, int x_off, int y_off, const int block_w, const int block_h, const VVCRect *subpic,const VVCRect *half_sb, const int dmvr_clip){ const VVCFrameContext *fc = lc->fc; int pic_width, pic_height; src += y_off * src_stride + x_off * (1 << ps); clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, half_sb, dmvr_clip); fc->vdsp.emulated_edge_mc(dst, src, dst_stride, src_stride, block_w, block_h, x_off, y_off, pic_width, pic_height);} static void sb_set_lr(VVCRect *sb, const int l, const int r){ sb->l = l; sb->r = r;} static void sb_wrap(VVCRect *sb, const int wrap){ sb_set_lr(sb, sb->l + wrap, sb->r + wrap);} static void emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame, int x_sb, int y_sb, int x_off, int y_off, int block_w, int block_h, const int wrap_enabled, const int is_chroma, const int extra_before, const int extra_after){ const VVCSPS *sps = src_frame->sps; const VVCPPS *pps = src_frame->pps; const int ps = sps->pixel_shift; const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; const int extra = extra_before + extra_after; const int dmvr_clip = x_sb != x_off || y_sb != y_off; const int dmvr_left = FFMAX(x_off, x_sb) - extra_before; const int dmvr_right = FFMIN(x_off, x_sb) + block_w + extra_after; const int left = x_off - extra_before; const int top = y_off - extra_before; const int pic_width = pps->width >> sps->hshift[is_chroma]; const int wrap = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]); const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps; VVCRect sb = { x_sb - extra_before, y_sb - extra_before, x_sb + block_w + extra_after, y_sb + block_h + extra_after }; VVCRect subpic; subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma); if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) { emulated_edge_no_wrap(lc, dst, src, src_stride, x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } if (dmvr_right <= 0) { sb_wrap(&sb, wrap); emulated_edge_no_wrap(lc, dst, src, src_stride, x_off + wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } if (dmvr_left >= pic_width) { sb_wrap(&sb, -wrap); emulated_edge_no_wrap(lc, dst, src, src_stride, x_off - wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } block_w += extra; block_h += extra; // half block are wrapped if (dmvr_left < 0 ) { const int w = -left; VVCRect half_sb = { sb.l + wrap, sb.t, 0 + wrap, sb.b }; emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, left + wrap, top, w, block_h, &subpic, &half_sb, dmvr_clip); sb_set_lr(&half_sb, 0, sb.r); emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, 0, top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); } else { const int w = pic_width - left; VVCRect half_sb = { sb.l, sb.t, pic_width, sb.b }; emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, left, top, w, block_h, &subpic, &half_sb, dmvr_clip); sb_set_lr(&half_sb, pic_width - wrap, sb.r - wrap); emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, pic_width - wrap , top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); } *src = dst + extra_before * dst_stride + (extra_before << ps); *src_stride = dst_stride;} #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) #define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_sb, y_sb, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) #define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, pred_w, pred_h, wrap_enabled, 0, \ BILINEAR_EXTRA_BEFORE, BILINEAR_EXTRA_AFTER) // part of 8.5.6.6 Weighted sample prediction processstatic int derive_weight_uni(int *denom, int *wx, int *ox, const VVCLocalContext *lc, const MvField *mvf, const int c_idx){ const VVCFrameContext *fc = lc->fc; const VVCPPS *pps = fc->ps.pps; const VVCSH *sh = &lc->sc->sh; const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag); if (weight_flag) { const int lx = mvf->pred_flag - PF_L0; const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; *denom = w->log2_denom[c_idx > 0]; *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]]; *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]]; } return weight_flag;} // part of 8.5.6.6 Weighted sample prediction processstatic 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){ const VVCFrameContext *fc = lc->fc; const VVCPPS *pps = fc->ps.pps; const VVCSH *sh = &lc->sc->sh; const int bcw_idx = mvf->bcw_idx; const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag); if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag)) return 0; if (bcw_idx) { *denom = 2; *w1 = bcw_w_lut[bcw_idx]; *w0 = 8 - *w1; *o0 = *o1 = 0; } else { const VVCPPS *pps = fc->ps.pps; const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; *denom = w->log2_denom[c_idx > 0]; *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]]; *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]]; *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]]; *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]]; } return 1;} #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac]) 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){ const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = ref->frame->data[c_idx]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const int is_chroma = !!c_idx; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);} 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){ const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = ref->frame->data[c_idx]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const int lx = mvf->pred_flag - PF_L0; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const Mv *mv = &mvf->mv[lx]; const int is_chroma = !!c_idx; const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; int denom, wx, ox; x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, denom, wx, ox, hf, vf, block_w); } else { fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w); }} 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){ const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const VVCFrame *refs[] = { ref0, ref1 }; int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET }; int denom, w0, w1, o0, o1; const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, pu->dmvr_flag); const int is_chroma = !!c_idx; const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; for (int i = L0; i <= L1; i++) { const Mv *mv = mvf->mv + i; const int mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const int my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int ox = x_off + (mv->x >> (4 + hs)); const int oy = y_off + (mv->y >> (4 + vs)); const VVCFrame *ref = refs[i]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const uint8_t *src = ref->frame->data[c_idx]; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; if (pu->dmvr_flag) { const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs)); const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs)); MC_EMULATED_EDGE_DMVR(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy); } else { MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); } fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w); if (sb_bdof_flag) fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h); } if (sb_bdof_flag) fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); else if (weight_flag) fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); else fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);} static const int8_t* inter_filter_scaled(const int scale, const int is_chroma, const int is_affine){#define SCALE_THRESHOLD_1 20480#define SCALE_THRESHOLD_2 28672 const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1); if (!is_chroma) { if (!is_affine) return &ff_vvc_inter_luma_filters[i + !!i][0][0]; //hpel 1 is not needed for scaled return &ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE + i][0][0]; } return &ff_vvc_inter_chroma_filters[i][0][0];}#define INTER_FILTER_SCALED(scale) inter_filter_scaled(scale, is_chroma, is_affine) #define SCALED_CHROMA_ADDIN(scale, collocated_flag) (is_chroma ? (collocated_flag ? 0 : 8 * (scale - (1 << 14))) : 0)#define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) ((((off - (scaling_off << shift)) << (4 + shift)) + ref_mv) * scale + add)#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))#define SCALED_STEP(scale) ((scale + 8) >> 4) 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){ const VVCFrameContext *fc = lc->fc; const VVCSPS *sps = fc->ps.sps; const int is_chroma = !!c_idx; const int hs = sps->hshift[c_idx]; const int vs = sps->vshift[c_idx]; const int left_offset = fc->ref->scaling_win.left_offset; const int top_offset = fc->ref->scaling_win.top_offset; const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag); const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag); const int refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs); const int refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs); *x = SCALED_REF(refx_sb, left_offset, hs); *y = SCALED_REF(refy_sb, top_offset, vs); *dx = SCALED_STEP(refp->scale[0]); *dy = SCALED_STEP(refp->scale[1]);} 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 w, const int h, const int is_chroma){ const int x_off = SCALED_INT(x); const int y_off = SCALED_INT(y); const int x_end = SCALED_INT(x + w * dx); const int y_end = SCALED_INT(y + h * dy); const int x_last = SCALED_INT(x + (w - 1) * dx); const int y_last = SCALED_INT(y + (h - 1) * dy); const int block_w = x_end - x_off + (x_end == x_last); const int block_h = *src_height = y_end - y_off + (y_end == y_last); const int wrap_enabled = 0; MC_EMULATED_EDGE(lc->edge_emu_buffer, src, src_stride, x_off, y_off);} 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){ const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = refp->ref->frame->data[c_idx]; ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; const int is_affine = pu->inter_affine_flag; const int is_chroma = !!c_idx; const int idx = av_log2(block_w) - 1; const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); int x, y, dx, dy, src_height; scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w);} 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){ const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = refp->ref->frame->data[c_idx]; ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; const int lx = mvf->pred_flag - PF_L0; const Mv *mv = &mvf->mv[lx]; const int is_affine = pu->inter_affine_flag; const int is_chroma = !!c_idx; const int idx = av_log2(block_w) - 1; const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); int denom, wx, ox, x, y, dx, dy, src_height; scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w); } else { fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w); }} 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){ int denom, w0, w1, o0, o1; const VVCFrameContext *fc = lc->fc; const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, lc->cu->pu.dmvr_flag); const VVCRefPic *refps[] = { refp0, refp1 }; int16_t *tmp[] = { lc->tmp, lc->tmp1 }; for (int i = L0; i <= L1; i++) { const Mv *mv = mvf->mv + i; const VVCRefPic *refp = refps[i]; if (refp->is_scaled) mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx); else mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx); } if (weight_flag) fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); else fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);} 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){ const VVCFrameContext *fc = lc->fc; const uint8_t *src = ref->frame->data[LUMA]; ptrdiff_t src_stride = ref->frame->linesize[LUMA]; uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET;Lines 1–500 of 1026. Load more
/* * VVC inter prediction * * Copyright (C) 2022 Nuo Mi * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "libavutil/frame.h" #include "data.h" #include "inter.h" #include "mvs.h" #include "refs.h" // +1 is enough, + 32 for asm alignment #define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32) static const int bcw_w_lut[] = {4, 5, 3, 10, -2}; static void subpic_get_rect(VVCRect *r, const VVCFrame *src_frame, const int subpic_idx, const int is_chroma) { const VVCSPS *sps = src_frame->sps; const VVCPPS *pps = src_frame->pps; const int hs = sps->hshift[is_chroma]; const int vs = sps->vshift[is_chroma]; r->l = pps->subpic_x[subpic_idx] >> hs; r->t = pps->subpic_y[subpic_idx] >> vs; r->r = r->l + (pps->subpic_width[subpic_idx] >> hs); r->b = r->t + (pps->subpic_height[subpic_idx] >> vs); } // clip to subblock and subpicture process in 8.5.6.3.2 Luma sample interpolation filtering process 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) { const int l = dmvr_clip ? FFMIN(FFMAX(subpic->l, sb->l), subpic->r - 1) : subpic->l; const int t = dmvr_clip ? FFMIN(FFMAX(subpic->t, sb->t), subpic->b - 1) : subpic->t; const int r = dmvr_clip ? FFMAX(FFMIN(subpic->r, sb->r), subpic->l + 1) : subpic->r; const int b = dmvr_clip ? FFMAX(FFMIN(subpic->b, sb->b), subpic->t + 1) : subpic->b; *x_off -= l; *y_off -= t; *pic_width = r - l; *pic_height = b - t; } static void emulated_edge_no_wrap(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, const int extra_before, const int extra_after, const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip) { const VVCFrameContext *fc = lc->fc; const int extra = extra_before + extra_after; int pic_width, pic_height; *src += y_off * *src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, sb, dmvr_clip); if (dmvr_clip || x_off < extra_before || y_off < extra_before || x_off >= pic_width - block_w - extra_after || y_off >= pic_height - block_h - extra_after) { const int ps = fc->ps.sps->pixel_shift; const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps; const int offset = extra_before * *src_stride + (extra_before << ps); const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps); fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before, pic_width, pic_height); *src = dst + buf_offset; *src_stride = edge_emu_stride; } } static void emulated_half(const VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride, const int ps, int x_off, int y_off, const int block_w, const int block_h, const VVCRect *subpic,const VVCRect *half_sb, const int dmvr_clip) { const VVCFrameContext *fc = lc->fc; int pic_width, pic_height; src += y_off * src_stride + x_off * (1 << ps); clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, half_sb, dmvr_clip); fc->vdsp.emulated_edge_mc(dst, src, dst_stride, src_stride, block_w, block_h, x_off, y_off, pic_width, pic_height); } static void sb_set_lr(VVCRect *sb, const int l, const int r) { sb->l = l; sb->r = r; } static void sb_wrap(VVCRect *sb, const int wrap) { sb_set_lr(sb, sb->l + wrap, sb->r + wrap); } static void emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame, int x_sb, int y_sb, int x_off, int y_off, int block_w, int block_h, const int wrap_enabled, const int is_chroma, const int extra_before, const int extra_after) { const VVCSPS *sps = src_frame->sps; const VVCPPS *pps = src_frame->pps; const int ps = sps->pixel_shift; const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; const int extra = extra_before + extra_after; const int dmvr_clip = x_sb != x_off || y_sb != y_off; const int dmvr_left = FFMAX(x_off, x_sb) - extra_before; const int dmvr_right = FFMIN(x_off, x_sb) + block_w + extra_after; const int left = x_off - extra_before; const int top = y_off - extra_before; const int pic_width = pps->width >> sps->hshift[is_chroma]; const int wrap = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]); const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps; VVCRect sb = { x_sb - extra_before, y_sb - extra_before, x_sb + block_w + extra_after, y_sb + block_h + extra_after }; VVCRect subpic; subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma); if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) { emulated_edge_no_wrap(lc, dst, src, src_stride, x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } if (dmvr_right <= 0) { sb_wrap(&sb, wrap); emulated_edge_no_wrap(lc, dst, src, src_stride, x_off + wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } if (dmvr_left >= pic_width) { sb_wrap(&sb, -wrap); emulated_edge_no_wrap(lc, dst, src, src_stride, x_off - wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); return; } block_w += extra; block_h += extra; // half block are wrapped if (dmvr_left < 0 ) { const int w = -left; VVCRect half_sb = { sb.l + wrap, sb.t, 0 + wrap, sb.b }; emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, left + wrap, top, w, block_h, &subpic, &half_sb, dmvr_clip); sb_set_lr(&half_sb, 0, sb.r); emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, 0, top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); } else { const int w = pic_width - left; VVCRect half_sb = { sb.l, sb.t, pic_width, sb.b }; emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, left, top, w, block_h, &subpic, &half_sb, dmvr_clip); sb_set_lr(&half_sb, pic_width - wrap, sb.r - wrap); emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, pic_width - wrap , top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); } *src = dst + extra_before * dst_stride + (extra_before << ps); *src_stride = dst_stride; } #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) #define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_sb, y_sb, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) #define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \ emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, pred_w, pred_h, wrap_enabled, 0, \ BILINEAR_EXTRA_BEFORE, BILINEAR_EXTRA_AFTER) // part of 8.5.6.6 Weighted sample prediction process static int derive_weight_uni(int *denom, int *wx, int *ox, const VVCLocalContext *lc, const MvField *mvf, const int c_idx) { const VVCFrameContext *fc = lc->fc; const VVCPPS *pps = fc->ps.pps; const VVCSH *sh = &lc->sc->sh; const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag); if (weight_flag) { const int lx = mvf->pred_flag - PF_L0; const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; *denom = w->log2_denom[c_idx > 0]; *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]]; *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]]; } return weight_flag; } // part of 8.5.6.6 Weighted sample prediction process 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) { const VVCFrameContext *fc = lc->fc; const VVCPPS *pps = fc->ps.pps; const VVCSH *sh = &lc->sc->sh; const int bcw_idx = mvf->bcw_idx; const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag); if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag)) return 0; if (bcw_idx) { *denom = 2; *w1 = bcw_w_lut[bcw_idx]; *w0 = 8 - *w1; *o0 = *o1 = 0; } else { const VVCPPS *pps = fc->ps.pps; const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; *denom = w->log2_denom[c_idx > 0]; *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]]; *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]]; *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]]; *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]]; } return 1; } #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac]) 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) { const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = ref->frame->data[c_idx]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const int is_chroma = !!c_idx; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); } 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) { const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = ref->frame->data[c_idx]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const int lx = mvf->pred_flag - PF_L0; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const Mv *mv = &mvf->mv[lx]; const int is_chroma = !!c_idx; const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; int denom, wx, ox; x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, denom, wx, ox, hf, vf, block_w); } else { fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w); } } 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) { const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const int hs = fc->ps.sps->hshift[c_idx]; const int vs = fc->ps.sps->vshift[c_idx]; const int idx = av_log2(block_w) - 1; const VVCFrame *refs[] = { ref0, ref1 }; int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET }; int denom, w0, w1, o0, o1; const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, pu->dmvr_flag); const int is_chroma = !!c_idx; const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; for (int i = L0; i <= L1; i++) { const Mv *mv = mvf->mv + i; const int mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); const int my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); const int ox = x_off + (mv->x >> (4 + hs)); const int oy = y_off + (mv->y >> (4 + vs)); const VVCFrame *ref = refs[i]; ptrdiff_t src_stride = ref->frame->linesize[c_idx]; const uint8_t *src = ref->frame->data[c_idx]; const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); const int8_t *vf = INTER_FILTER(hpel_if_idx, my); const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; if (pu->dmvr_flag) { const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs)); const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs)); MC_EMULATED_EDGE_DMVR(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy); } else { MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); } fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w); if (sb_bdof_flag) fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h); } if (sb_bdof_flag) fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); else if (weight_flag) fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); else fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); } static const int8_t* inter_filter_scaled(const int scale, const int is_chroma, const int is_affine) { #define SCALE_THRESHOLD_1 20480 #define SCALE_THRESHOLD_2 28672 const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1); if (!is_chroma) { if (!is_affine) return &ff_vvc_inter_luma_filters[i + !!i][0][0]; //hpel 1 is not needed for scaled return &ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE + i][0][0]; } return &ff_vvc_inter_chroma_filters[i][0][0]; } #define INTER_FILTER_SCALED(scale) inter_filter_scaled(scale, is_chroma, is_affine) #define SCALED_CHROMA_ADDIN(scale, collocated_flag) (is_chroma ? (collocated_flag ? 0 : 8 * (scale - (1 << 14))) : 0) #define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) ((((off - (scaling_off << shift)) << (4 + shift)) + ref_mv) * scale + add) #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)) #define SCALED_STEP(scale) ((scale + 8) >> 4) 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) { const VVCFrameContext *fc = lc->fc; const VVCSPS *sps = fc->ps.sps; const int is_chroma = !!c_idx; const int hs = sps->hshift[c_idx]; const int vs = sps->vshift[c_idx]; const int left_offset = fc->ref->scaling_win.left_offset; const int top_offset = fc->ref->scaling_win.top_offset; const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag); const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag); const int refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs); const int refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs); *x = SCALED_REF(refx_sb, left_offset, hs); *y = SCALED_REF(refy_sb, top_offset, vs); *dx = SCALED_STEP(refp->scale[0]); *dy = SCALED_STEP(refp->scale[1]); } 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 w, const int h, const int is_chroma) { const int x_off = SCALED_INT(x); const int y_off = SCALED_INT(y); const int x_end = SCALED_INT(x + w * dx); const int y_end = SCALED_INT(y + h * dy); const int x_last = SCALED_INT(x + (w - 1) * dx); const int y_last = SCALED_INT(y + (h - 1) * dy); const int block_w = x_end - x_off + (x_end == x_last); const int block_h = *src_height = y_end - y_off + (y_end == y_last); const int wrap_enabled = 0; MC_EMULATED_EDGE(lc->edge_emu_buffer, src, src_stride, x_off, y_off); } 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) { const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = refp->ref->frame->data[c_idx]; ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; const int is_affine = pu->inter_affine_flag; const int is_chroma = !!c_idx; const int idx = av_log2(block_w) - 1; const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); int x, y, dx, dy, src_height; scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w); } 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) { const VVCFrameContext *fc = lc->fc; const PredictionUnit *pu = &lc->cu->pu; const uint8_t *src = refp->ref->frame->data[c_idx]; ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; const int lx = mvf->pred_flag - PF_L0; const Mv *mv = &mvf->mv[lx]; const int is_affine = pu->inter_affine_flag; const int is_chroma = !!c_idx; const int idx = av_log2(block_w) - 1; const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); int denom, wx, ox, x, y, dx, dy, src_height; scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w); } else { fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w); } } 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) { int denom, w0, w1, o0, o1; const VVCFrameContext *fc = lc->fc; const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, lc->cu->pu.dmvr_flag); const VVCRefPic *refps[] = { refp0, refp1 }; int16_t *tmp[] = { lc->tmp, lc->tmp1 }; for (int i = L0; i <= L1; i++) { const Mv *mv = mvf->mv + i; const VVCRefPic *refp = refps[i]; if (refp->is_scaled) mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx); else mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx); } if (weight_flag) fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); else fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); } 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) { const VVCFrameContext *fc = lc->fc; const uint8_t *src = ref->frame->data[LUMA]; ptrdiff_t src_stride = ref->frame->linesize[LUMA]; uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET;