Commit 9f2030f3a8 for ffmpeg
commit 9f2030f3a8c75f846d852db4df506d362e8921ce
Author: Wu Jianhua <toqsxw@outlook.com>
Date: Tue Apr 15 04:48:02 2025 +0800
avcodec/vvc/filter_template: fix alf_recon_coeff_and_clip function for high bitdepth
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
diff --git a/libavcodec/vvc/ctu.h b/libavcodec/vvc/ctu.h
index 060479762f..c5b5b57086 100644
--- a/libavcodec/vvc/ctu.h
+++ b/libavcodec/vvc/ctu.h
@@ -461,7 +461,8 @@ typedef struct VVCLocalContext {
DECLARE_ALIGNED(32, uint8_t, buffer_chroma)[(MAX_CTU_SIZE + 2 * ALF_PADDING_SIZE) * EDGE_EMU_BUFFER_STRIDE * 2];
DECLARE_ALIGNED(32, int32_t, gradient_tmp)[ALF_GRADIENT_SIZE * ALF_GRADIENT_SIZE * ALF_NUM_DIR];
DECLARE_ALIGNED(32, int16_t, coeff_tmp)[ALF_MAX_FILTER_SIZE];
- DECLARE_ALIGNED(32, int16_t, clip_tmp)[ALF_MAX_FILTER_SIZE];
+ /* *2: tpixel is int for bit depths > 12 */
+ DECLARE_ALIGNED(32, int16_t, clip_tmp)[ALF_MAX_FILTER_SIZE * 2];
} alf; ///< only accessed in ff_vvc_alf_filter() during the alf processing stage
};
} VVCLocalContext;
diff --git a/libavcodec/vvc/filter.c b/libavcodec/vvc/filter.c
index 41ce3a3fe2..bfbbfced7d 100644
--- a/libavcodec/vvc/filter.c
+++ b/libavcodec/vvc/filter.c
@@ -1027,6 +1027,11 @@ static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *sr
int16_t *coeff = lc->alf.coeff_tmp;
int16_t *clip = lc->alf.clip_tmp;
+ av_assert0(ALF_MAX_FILTER_SIZE * sizeof(*coeff) <= sizeof(lc->alf.coeff_tmp));
+ av_assert0(ALF_MAX_FILTER_SIZE *
+ (fc->ps.sps->bit_depth > 12 ? sizeof(int) : sizeof(int16_t)) <=
+ sizeof(lc->alf.clip_tmp));
+
alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf);
fc->vvcdsp.alf.filter[LUMA](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 c9bc7cdb0c..a72d4a2f47 100644
--- a/libavcodec/vvc/filter_template.c
+++ b/libavcodec/vvc/filter_template.c
@@ -370,7 +370,7 @@ static void FUNC(alf_classify)(int *class_idx, int *transpose_idx,
}
-static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *clip,
+static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *_clip,
const int *class_idx, const int *transpose_idx, const int size,
const int16_t *coeff_set, const uint8_t *clip_idx_set, const uint8_t *class_to_filt)
{
@@ -381,10 +381,12 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *clip,
{ 9, 8, 10, 4, 3, 7, 11, 5, 1, 0, 2, 6 },
};
- const int16_t clip_set[] = {
+ const tpixel clip_set[] = {
1 << BIT_DEPTH, 1 << (BIT_DEPTH - 3), 1 << (BIT_DEPTH - 5), 1 << (BIT_DEPTH - 7)
};
+ tpixel *clip = (tpixel *)_clip;
+
for (int i = 0; i < size; i++) {
const int16_t *src_coeff = coeff_set + class_to_filt[class_idx[i]] * ALF_NUM_COEFF_LUMA;
const uint8_t *clip_idx = clip_idx_set + class_idx[i] * ALF_NUM_COEFF_LUMA;