Commit 778f3a5ee0 for ffmpeg

commit 778f3a5ee02947727504a161c8a62849b38373ed
Author: Wu Jianhua <toqsxw@outlook.com>
Date:   Tue Apr 15 04:47:55 2025 +0800

    avcodec/vvc/dsp: add get_clip_from_idx for high bitdepth

    Signed-off-by: Wu Jianhua <toqsxw@outlook.com>

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index e0953f2e01..b14767b003 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -167,6 +167,7 @@ typedef struct VVCALFDSPContext {
         int vb_pos, int *gradient_tmp);
     void (*recon_coeff_and_clip)(int16_t *coeff, int16_t *clip, const int *class_idx, const int *transpose_idx, int size,
         const int16_t *coeff_set, const uint8_t *clip_idx_set, const uint8_t *class_to_filt);
+    void (*get_clip_from_idx)(int16_t *clip, const uint8_t *clip_idx);
 } VVCALFDSPContext;

 typedef struct VVCDSPContext {
diff --git a/libavcodec/vvc/filter.c b/libavcodec/vvc/filter.c
index e3131cf808..41ce3a3fe2 100644
--- a/libavcodec/vvc/filter.c
+++ b/libavcodec/vvc/filter.c
@@ -1031,14 +1031,6 @@ static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *sr
     fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
 }

-static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx)
-{
-    const VVCSPS *sps  = fc->ps.sps;
-    const int offset[] = {0, 3, 5, 7};
-
-    return 1 << (sps->bit_depth - offset[idx]);
-}
-
 static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
     const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx,
     const int width, const int height, const int vb_pos, const ALFParams *alf)
@@ -1048,11 +1040,13 @@ static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *
     const VVCALF *aps             = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma];
     const int idx                 = alf->alf_ctb_filter_alt_idx[c_idx - 1];
     const int16_t *coeff          = aps->chroma_coeff[idx];
-    int16_t clip[ALF_NUM_COEFF_CHROMA];
-
-    for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++)
-        clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]);
+    union {
+        int16_t narrow[ALF_NUM_COEFF_CHROMA * 2];
+        int wide[ALF_NUM_COEFF_CHROMA];
+    } clips;
+    int16_t *clip = fc->ps.sps->bit_depth > 12 ? (int16_t *)clips.wide : clips.narrow;

+    fc->vvcdsp.alf.get_clip_from_idx(clip, aps->chroma_clip_idx[idx]);
     fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
 }

diff --git a/libavcodec/vvc/filter_template.c b/libavcodec/vvc/filter_template.c
index 6dd7310089..c9bc7cdb0c 100644
--- a/libavcodec/vvc/filter_template.c
+++ b/libavcodec/vvc/filter_template.c
@@ -397,6 +397,16 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *clip,
     }
 }

+static void FUNC(alf_get_clip_from_idx)(int16_t *_clip, const uint8_t *clip_idx)
+{
+    tpixel *clip = (tpixel *)_clip;
+    const int offset[] = { 0, 3, 5, 7 };
+
+    for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++) {
+        clip[i] = 1 << (BIT_DEPTH - offset[clip_idx[i]]);
+    }
+}
+
 #undef ALF_DIR_HORZ
 #undef ALF_DIR_VERT
 #undef ALF_DIR_DIGA0
@@ -854,9 +864,10 @@ static void FUNC(ff_vvc_sao_dsp_init)(VVCSAODSPContext *const sao)

 static void FUNC(ff_vvc_alf_dsp_init)(VVCALFDSPContext *const alf)
 {
-    alf->filter[LUMA]    = FUNC(alf_filter_luma);
-    alf->filter[CHROMA]  = FUNC(alf_filter_chroma);
-    alf->filter_cc       = FUNC(alf_filter_cc);
-    alf->classify        = FUNC(alf_classify);
+    alf->filter[LUMA]         = FUNC(alf_filter_luma);
+    alf->filter[CHROMA]       = FUNC(alf_filter_chroma);
+    alf->filter_cc            = FUNC(alf_filter_cc);
+    alf->classify             = FUNC(alf_classify);
     alf->recon_coeff_and_clip = FUNC(alf_recon_coeff_and_clip);
+    alf->get_clip_from_idx    = FUNC(alf_get_clip_from_idx);
 }