PR #26177 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26177 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26177.patch
Omitting geq's alpha expression currently produces transparent output because geq_init() constructs the default before the negotiated pixel depth is available. For example, the reproducer in #26106 produces alpha bytes `0 0` instead of `255 255`. Generate and parse only the implicit alpha expression in geq_config_props(), using the integer maximum or 1 for floating-point formats. Keep explicit expressions parsed during initialization, propagate errors, and free previous default expressions before replacement on reconfiguration. Add eight sample-independent FATE tests covering omitted alpha in 8/10/16-bit YUV and 8/12-bit/floating-point RGB, plus explicit spatial alpha expressions in integer and floating-point formats. All pass with one and four threads; the six omitted-alpha tests fail on unmodified master. Reference checksums were independently verified against expected raw pixels. Additional raw-pixel checks passed 136 combinations across all 17 supported alpha formats, and eight representative formats without alpha remain byte-identical. The regression was verified by building ecc16d893dc0 and its immediate parent, 60a45713e7bc: the parent produces opaque alpha and the introducing commit produces zero alpha. The reported command also reproduces on release/9.1, 9.0, 8.1, 8.0, 7.1, 6.1, 5.1, and 4.4. Fixes #26106. >From b27386ed0ae8b9440e9dd289fa868d13e9ccb37d Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 18 Nov 2026 15:30:20 +0000 Subject: [PATCH] avfilter/geq: defer default alpha expression until format configuration The pixel depth is not known in geq_init(), so the default alpha expression evaluates to zero for every supported format. Generate and parse the default in geq_config_props() after the depth has been set, using the integer maximum or 1 for floating-point formats. Keep parsing user-supplied expressions during initialization. Leave the alpha option unset when using the default so that reconfiguration can regenerate it, freeing previous expressions before replacing them. Add FATE coverage for omitted alpha in 8/10/16-bit YUV and 8/12-bit and floating-point RGB, including transparent input. Also cover explicit alpha expressions in integer and floating-point formats. Fixes: ecc16d893dc0ee8b74bb179fedb5d077419eea23 Fixes: #26106 Assisted-by: Fairy --- libavfilter/vf_geq.c | 28 ++++++++++++++----- tests/fate/filter-video.mak | 24 ++++++++++++++++ .../fate/filter-geq-alpha-explicit-gbrapf32 | 6 ++++ .../fate/filter-geq-alpha-explicit-yuva444p | 6 ++++ tests/ref/fate/filter-geq-alpha-gbrap | 6 ++++ tests/ref/fate/filter-geq-alpha-gbrap12 | 6 ++++ tests/ref/fate/filter-geq-alpha-gbrapf32 | 6 ++++ tests/ref/fate/filter-geq-alpha-yuva444p | 6 ++++ tests/ref/fate/filter-geq-alpha-yuva444p10 | 6 ++++ tests/ref/fate/filter-geq-alpha-yuva444p16 | 6 ++++ 10 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 tests/ref/fate/filter-geq-alpha-explicit-gbrapf32 create mode 100644 tests/ref/fate/filter-geq-alpha-explicit-yuva444p create mode 100644 tests/ref/fate/filter-geq-alpha-gbrap create mode 100644 tests/ref/fate/filter-geq-alpha-gbrap12 create mode 100644 tests/ref/fate/filter-geq-alpha-gbrapf32 create mode 100644 tests/ref/fate/filter-geq-alpha-yuva444p create mode 100644 tests/ref/fate/filter-geq-alpha-yuva444p10 create mode 100644 tests/ref/fate/filter-geq-alpha-yuva444p16 diff --git a/libavfilter/vf_geq.c b/libavfilter/vf_geq.c index fc3dd6740ef..8b58262aa22 100644 --- a/libavfilter/vf_geq.c +++ b/libavfilter/vf_geq.c @@ -27,7 +27,6 @@ */ #include "libavutil/avassert.h" -#include "libavutil/avstring.h" #include "libavutil/eval.h" #include "libavutil/mem.h" #include "libavutil/opt.h" @@ -281,11 +280,6 @@ static av_cold int geq_init(AVFilterContext *ctx) if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]); } - if (!geq->expr_str[A] && geq->bps != 32) { - geq->expr_str[A] = av_asprintf("%d", (1<<geq->bps) - 1); - } else if (!geq->expr_str[A]) { - geq->expr_str[A] = av_asprintf("%f", 1.f); - } if (!geq->expr_str[G]) geq->expr_str[G] = av_strdup("g(X,Y)"); if (!geq->expr_str[B]) @@ -296,7 +290,7 @@ static av_cold int geq_init(AVFilterContext *ctx) if (geq->is_rgb ? (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R]) : - (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) { + (!geq->expr_str[U] || !geq->expr_str[V])) { ret = AVERROR(ENOMEM); goto end; } @@ -321,6 +315,10 @@ static av_cold int geq_init(AVFilterContext *ctx) NULL }; int counter[10] = {0}; + /* The default alpha expression depends on the negotiated format. */ + if (plane == A && !geq->expr_str[A]) + continue; + for (int i = 0; i < MAX_NB_THREADS; i++) { ret = av_expr_parse(&geq->e[plane][i], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names, NULL, NULL, func2_names, func2, 0, ctx); @@ -387,6 +385,22 @@ static int geq_config_props(AVFilterLink *inlink) geq->vsub = desc->log2_chroma_h; geq->bps = desc->comp[0].depth; geq->planes = desc->nb_components; + + if (!geq->expr_str[A]) { + char alpha_expr[8]; + int ret; + + snprintf(alpha_expr, sizeof(alpha_expr), "%d", + geq->bps == 32 ? 1 : (1 << geq->bps) - 1); + for (int i = 0; i < MAX_NB_THREADS; i++) { + av_expr_free(geq->e[A][i]); + geq->e[A][i] = NULL; + ret = av_expr_parse(&geq->e[A][i], alpha_expr, NULL, + NULL, NULL, NULL, NULL, 0, inlink->dst); + if (ret < 0) + return ret; + } + } return 0; } diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 7862b54981b..34d49d6698c 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -96,6 +96,30 @@ fate-filter-lavd-testsrc: CMD = framecrc -f lavfi -i testsrc=r=7:n=2:d=10 FATE_FILTER-$(call FILTERFRAMECRC, TESTSRC2) += $(addprefix fate-filter-testsrc2-, yuv420p yuv444p rgb24 rgba) fate-filter-testsrc2-%: CMD = framecrc -lavfi testsrc2=r=7:d=10 -pix_fmt $(word 4, $(subst -, ,$(@))) +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-yuva444p +fate-filter-geq-alpha-yuva444p: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=yuva444p,geq=lum=0:a=0,geq=lum=50:cb=60:cr=70,scale" -pix_fmt yuva444p + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-yuva444p10 +fate-filter-geq-alpha-yuva444p10: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=yuva444p10,geq=lum=0:a=0,geq=lum=50:cb=60:cr=70,scale" -pix_fmt yuva444p10le + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-yuva444p16 +fate-filter-geq-alpha-yuva444p16: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=yuva444p16,geq=lum=0:a=0,geq=lum=50:cb=60:cr=70,scale" -pix_fmt yuva444p16le + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-gbrap +fate-filter-geq-alpha-gbrap: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=gbrap,geq=r=0:g=0:b=0:a=0,geq=r=50:g=60:b=70,scale" -pix_fmt gbrap + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-gbrap12 +fate-filter-geq-alpha-gbrap12: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=gbrap12,geq=r=0:g=0:b=0:a=0,geq=r=50:g=60:b=70,scale" -pix_fmt gbrap12le + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-gbrapf32 +fate-filter-geq-alpha-gbrapf32: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=gbrapf32,geq=r=0:g=0:b=0:a=0,geq=r=0.25:g=0.5:b=0.75,scale" -pix_fmt gbrapf32le + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-explicit-yuva444p +fate-filter-geq-alpha-explicit-yuva444p: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=yuva444p,geq=lum=50:cb=60:cr=70:a=X+4*Y,scale" -pix_fmt yuva444p + +FATE_FILTER-$(call FILTERFRAMECRC, NULLSRC FORMAT GEQ SCALE) += fate-filter-geq-alpha-explicit-gbrapf32 +fate-filter-geq-alpha-explicit-gbrapf32: CMD = framecrc -lavfi "nullsrc=s=4x4:r=1:d=1,format=gbrapf32,geq=r=0.25:g=0.5:b=0.75:a=(X+4*Y)/16,scale" -pix_fmt gbrapf32le + FATE_FILTER-$(call FILTERFRAMECRC, ALLRGB) += fate-filter-allrgb fate-filter-allrgb: CMD = framecrc -lavfi allrgb=rate=5:duration=1 -pix_fmt rgb24 diff --git a/tests/ref/fate/filter-geq-alpha-explicit-gbrapf32 b/tests/ref/fate/filter-geq-alpha-explicit-gbrapf32 new file mode 100644 index 00000000000..2e739f62fc3 --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-explicit-gbrapf32 @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 256, 0xe11c20a9 diff --git a/tests/ref/fate/filter-geq-alpha-explicit-yuva444p b/tests/ref/fate/filter-geq-alpha-explicit-yuva444p new file mode 100644 index 00000000000..a994cf53b2f --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-explicit-yuva444p @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 64, 0xb6570bb8 diff --git a/tests/ref/fate/filter-geq-alpha-gbrap b/tests/ref/fate/filter-geq-alpha-gbrap new file mode 100644 index 00000000000..7212ee15269 --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-gbrap @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 64, 0x59361b30 diff --git a/tests/ref/fate/filter-geq-alpha-gbrap12 b/tests/ref/fate/filter-geq-alpha-gbrap12 new file mode 100644 index 00000000000..8b627f94742 --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-gbrap12 @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 128, 0xc16c1c20 diff --git a/tests/ref/fate/filter-geq-alpha-gbrapf32 b/tests/ref/fate/filter-geq-alpha-gbrapf32 new file mode 100644 index 00000000000..b2aa986cfec --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-gbrapf32 @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 256, 0x4b2223b0 diff --git a/tests/ref/fate/filter-geq-alpha-yuva444p b/tests/ref/fate/filter-geq-alpha-yuva444p new file mode 100644 index 00000000000..d0efbcbff3d --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-yuva444p @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 64, 0x3b361b30 diff --git a/tests/ref/fate/filter-geq-alpha-yuva444p10 b/tests/ref/fate/filter-geq-alpha-yuva444p10 new file mode 100644 index 00000000000..fa4f405007d --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-yuva444p10 @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 128, 0x796c1b60 diff --git a/tests/ref/fate/filter-geq-alpha-yuva444p16 b/tests/ref/fate/filter-geq-alpha-yuva444p16 new file mode 100644 index 00000000000..040845703d9 --- /dev/null +++ b/tests/ref/fate/filter-geq-alpha-yuva444p16 @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 4x4 +#sar 0: 1/1 +0, 0, 0, 1, 128, 0x757b2b20 -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
