From e7867075c4dc4bb244798c096e484d3cfaf10254 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Sun, 3 Aug 2025 19:34:08 +0200 Subject: [PATCH 01/39] lavfi: add a flag for filters that support premultiplied alpha Signed-off-by: Nicolas George --- libavfilter/avfilter.c | 7 +++++++ libavfilter/filters.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 5bcf0b4ef7..2f425b529c 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1097,6 +1097,13 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) link->time_base); } + if ((frame->alpha_mode == AVALPHA_MODE_PREMULTIPLIED) && + !(link->dstpad->flags & AVFILTERPAD_FLAG_ACCEPT_PREMULTIPLIED)) { + av_log(link->dst, AV_LOG_ERROR, "Frames with premultiplied alpha are not supported by this filter.\n"); + av_frame_free(&frame); + return AVERROR_PATCHWELCOME; + } + li->frame_blocked_in = li->frame_wanted_out = 0; li->l.frame_count_in++; li->l.sample_count_in += frame->nb_samples; diff --git a/libavfilter/filters.h b/libavfilter/filters.h index 11152cfabf..8b431bd457 100644 --- a/libavfilter/filters.h +++ b/libavfilter/filters.h @@ -62,6 +62,12 @@ struct AVFilterPad { */ #define AVFILTERPAD_FLAG_FREE_NAME (1 << 1) + /** + * The filter is capable of handling frame with premultiplied alpha + * without producing garbled output + */ +#define AVFILTERPAD_FLAG_ACCEPT_PREMULTIPLIED (1 << 2) + /** * A combination of AVFILTERPAD_FLAG_* flags. */ -- 2.47.2