This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 0293b8a0278ecf693048df1b33658d3219201140 Author: Michael Niedermayer <[email protected]> AuthorDate: Wed Sep 23 05:46:42 2026 +0200 Commit: michaelni <[email protected]> CommitDate: Sat Sep 26 11:36:30 2026 +0000 avfilter/drawutils: cover the alpha plane fully when blending Blending took the colour's own alpha as the value written into the alpha plane, weighted by that same alpha once more, so a translucent colour left less alpha behind than it covered: half transparent red over a transparent canvas ended with alpha 64 instead of 128, and drawn over opaque content it even punched a hole into the alpha plane. The colour's transparency is already part of the coverage, so the alpha plane takes full coverage, which is source-over compositing. The drawutils test program checks this and runs under FATE. Assisted-by: Claude --- libavfilter/drawutils.c | 42 +++++-- libavfilter/tests/drawutils.c | 15 +++ tests/fate/filter-video.mak | 4 + tests/ref/fate/filter-drawutils | 270 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 319 insertions(+), 12 deletions(-) diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c index 75bf8f4755..b1ac440b06 100644 --- a/libavfilter/drawutils.c +++ b/libavfilter/drawutils.c @@ -375,11 +375,28 @@ static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha, } } +/* the colour as blended: its transparency is already in the coverage, so it covers the alpha plane fully */ +static FFDrawColor blended_color(FFDrawContext *draw, const FFDrawColor *color) +{ + const AVPixFmtDescriptor *desc = draw->desc; + const AVComponentDescriptor *alpha = &desc->comp[desc->nb_components - 1]; + FFDrawColor over = *color; + + if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && draw->flags & FF_DRAW_PROCESS_ALPHA) { + if (alpha->depth <= 8) + over.comp[alpha->plane].u8[alpha->offset] = 0xFF; + else + over.comp[alpha->plane].u16[alpha->offset / 2] = (1 << alpha->depth) - 1; + } + return over; +} + void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h) { + FFDrawColor over = blended_color(draw, color); unsigned alpha, nb_planes, nb_comp; int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom; uint8_t *p0, *p; @@ -419,11 +436,11 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, p = p0 + offset; if (top) { if (depth <= 8) { - blend_line(p, color->comp[plane].u8[index], alpha >> 1, + blend_line(p, over.comp[plane].u8[index], alpha >> 1, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); } else { - blend_line16(p, color->comp[plane].u16[index], alpha >> 1, + blend_line16(p, over.comp[plane].u16[index], alpha >> 1, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); } @@ -431,14 +448,14 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, } if (depth <= 8) { for (int y = 0; y < h_sub; y++) { - blend_line(p, color->comp[plane].u8[index], alpha, + blend_line(p, over.comp[plane].u8[index], alpha, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); p += dst_linesize[plane]; } } else { for (int y = 0; y < h_sub; y++) { - blend_line16(p, color->comp[plane].u16[index], alpha, + blend_line16(p, over.comp[plane].u16[index], alpha, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); p += dst_linesize[plane]; @@ -446,11 +463,11 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, } if (bottom) { if (depth <= 8) { - blend_line(p, color->comp[plane].u8[index], alpha >> 1, + blend_line(p, over.comp[plane].u8[index], alpha >> 1, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); } else { - blend_line16(p, color->comp[plane].u16[index], alpha >> 1, + blend_line16(p, over.comp[plane].u16[index], alpha >> 1, draw->pixelstep[plane], w_sub, draw->hsub[plane], left, right); } @@ -559,6 +576,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0) { + FFDrawColor over = blended_color(draw, color); unsigned alpha, nb_planes, nb_comp; int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom; uint8_t *p; @@ -601,13 +619,13 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, if (top) { if (depth <= 8) { blend_line_hv(p, draw->pixelstep[plane], - color->comp[plane].u8[index], alpha, + over.comp[plane].u8[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, top); } else { blend_line_hv16(p, draw->pixelstep[plane], - color->comp[plane].u16[index], alpha, + over.comp[plane].u16[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, top); @@ -618,7 +636,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, if (depth <= 8) { for (int y = 0; y < h_sub; y++) { blend_line_hv(p, draw->pixelstep[plane], - color->comp[plane].u8[index], alpha, + over.comp[plane].u8[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, 1 << draw->vsub[plane]); @@ -628,7 +646,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, } else { for (int y = 0; y < h_sub; y++) { blend_line_hv16(p, draw->pixelstep[plane], - color->comp[plane].u16[index], alpha, + over.comp[plane].u16[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, 1 << draw->vsub[plane]); @@ -639,13 +657,13 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, if (bottom) { if (depth <= 8) { blend_line_hv(p, draw->pixelstep[plane], - color->comp[plane].u8[index], alpha, + over.comp[plane].u8[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, bottom); } else { blend_line_hv16(p, draw->pixelstep[plane], - color->comp[plane].u16[index], alpha, + over.comp[plane].u16[index], alpha, m, mask_linesize, l2depth, w_sub, draw->hsub[plane], draw->vsub[plane], xm0, left, right, bottom); diff --git a/libavfilter/tests/drawutils.c b/libavfilter/tests/drawutils.c index 2ee46f3a43..fd41ed84fd 100644 --- a/libavfilter/tests/drawutils.c +++ b/libavfilter/tests/drawutils.c @@ -50,5 +50,20 @@ int main(void) } printf("ok\n"); } + + ff_draw_init(&draw, AV_PIX_FMT_RGBA, FF_DRAW_PROCESS_ALPHA); + ff_draw_color(&draw, &color, (uint8_t[]) { 255, 0, 0, 128 }); + for (int pass = 0; pass < 2; pass++) { + uint8_t pixel[4] = { 0 }; + uint8_t *dst[4] = { pixel }, mask = 0xFF; + int linesize[4] = { 4 }; + + if (pass) + ff_blend_rectangle(&draw, &color, dst, linesize, 1, 1, 0, 0, 1, 1); + else + ff_blend_mask(&draw, &color, dst, linesize, 1, 1, &mask, 1, 1, 1, 3, 0, 0, 0); + printf("half transparent red over transparent rgba by %s: %d %d %d %d\n", + pass ? "rectangle" : "mask", pixel[0], pixel[1], pixel[2], pixel[3]); + } return 0; } diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index b0284c9813..fa421a315f 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -501,6 +501,10 @@ fate-filter-fps-down-eof-pass: CMD = framecrc -lavfi testsrc2=r=7:d=3.5,fps=3:eo fate-filter-fps-start-drop: CMD = framecrc -lavfi testsrc2=r=7:d=3.5,fps=3:start_time=1.5 fate-filter-fps-start-fill: CMD = framecrc -lavfi testsrc2=r=7:d=1.5,setpts=PTS+14,fps=3:start_time=1.5 +FATE_FILTER-yes += fate-filter-drawutils +fate-filter-drawutils: libavfilter/tests/drawutils$(EXESUF) +fate-filter-drawutils: CMD = run libavfilter/tests/drawutils$(EXESUF) + DRAWVG_SCRIPT_ALL = $(SRC_PATH)/tests/ref/lavf/drawvg.all FATE_FILTER-$(CONFIG_DRAWVG_FILTER) += fate-filter-drawvg-interpreter diff --git a/tests/ref/fate/filter-drawutils b/tests/ref/fate/filter-drawutils new file mode 100644 index 0000000000..cef5a2ead4 --- /dev/null +++ b/tests/ref/fate/filter-drawutils @@ -0,0 +1,270 @@ +Testing yuv420p... ok +Testing yuyv422... no: Function not implemented +Testing rgb24... ok +Testing bgr24... ok +Testing yuv422p... ok +Testing yuv444p... ok +Testing yuv410p... ok +Testing yuv411p... ok +Testing gray... ok +Testing monow... no: Function not implemented +Testing monob... no: Function not implemented +Testing pal8... no: Function not implemented +Testing yuvj420p... ok +Testing yuvj422p... ok +Testing yuvj444p... ok +Testing uyvy422... no: Function not implemented +Testing uyyvyy411... no: Function not implemented +Testing bgr8... no: Function not implemented +Testing bgr4... no: Function not implemented +Testing bgr4_byte... no: Function not implemented +Testing rgb8... no: Function not implemented +Testing rgb4... no: Function not implemented +Testing rgb4_byte... no: Function not implemented +Testing nv12... ok +Testing nv21... ok +Testing argb... ok +Testing rgba... ok +Testing abgr... ok +Testing bgra... ok +Testing gray16be... no: Function not implemented +Testing gray16le... ok +Testing yuv440p... ok +Testing yuvj440p... ok +Testing yuva420p... ok +Testing rgb48be... no: Function not implemented +Testing rgb48le... ok +Testing rgb565be... no: Function not implemented +Testing rgb565le... no: Function not implemented +Testing rgb555be... no: Function not implemented +Testing rgb555le... no: Function not implemented +Testing bgr565be... no: Function not implemented +Testing bgr565le... no: Function not implemented +Testing bgr555be... no: Function not implemented +Testing bgr555le... no: Function not implemented +Testing vaapi... no: Function not implemented +Testing yuv420p16le... ok +Testing yuv420p16be... no: Function not implemented +Testing yuv422p16le... ok +Testing yuv422p16be... no: Function not implemented +Testing yuv444p16le... ok +Testing yuv444p16be... no: Function not implemented +Testing dxva2_vld... no: Function not implemented +Testing rgb444le... no: Function not implemented +Testing rgb444be... no: Function not implemented +Testing bgr444le... no: Function not implemented +Testing bgr444be... no: Function not implemented +Testing ya8... ok +Testing bgr48be... no: Function not implemented +Testing bgr48le... ok +Testing yuv420p9be... no: Function not implemented +Testing yuv420p9le... ok +Testing yuv420p10be... no: Function not implemented +Testing yuv420p10le... ok +Testing yuv422p10be... no: Function not implemented +Testing yuv422p10le... ok +Testing yuv444p9be... no: Function not implemented +Testing yuv444p9le... ok +Testing yuv444p10be... no: Function not implemented +Testing yuv444p10le... ok +Testing yuv422p9be... no: Function not implemented +Testing yuv422p9le... ok +Testing gbrp... ok +Testing gbrp9be... no: Function not implemented +Testing gbrp9le... ok +Testing gbrp10be... no: Function not implemented +Testing gbrp10le... ok +Testing gbrp16be... no: Function not implemented +Testing gbrp16le... ok +Testing yuva422p... ok +Testing yuva444p... ok +Testing yuva420p9be... no: Function not implemented +Testing yuva420p9le... ok +Testing yuva422p9be... no: Function not implemented +Testing yuva422p9le... ok +Testing yuva444p9be... no: Function not implemented +Testing yuva444p9le... ok +Testing yuva420p10be... no: Function not implemented +Testing yuva420p10le... ok +Testing yuva422p10be... no: Function not implemented +Testing yuva422p10le... ok +Testing yuva444p10be... no: Function not implemented +Testing yuva444p10le... ok +Testing yuva420p16be... no: Function not implemented +Testing yuva420p16le... ok +Testing yuva422p16be... no: Function not implemented +Testing yuva422p16le... ok +Testing yuva444p16be... no: Function not implemented +Testing yuva444p16le... ok +Testing vdpau... no: Function not implemented +Testing xyz12le... no: Function not implemented +Testing xyz12be... no: Function not implemented +Testing nv16... ok +Testing nv20le... ok +Testing nv20be... no: Function not implemented +Testing rgba64be... no: Function not implemented +Testing rgba64le... no: Function not implemented +Testing bgra64be... no: Function not implemented +Testing bgra64le... no: Function not implemented +Testing yvyu422... no: Function not implemented +Testing ya16be... no: Function not implemented +Testing ya16le... ok +Testing gbrap... ok +Testing gbrap16be... no: Function not implemented +Testing gbrap16le... ok +Testing qsv... no: Function not implemented +Testing mmal... no: Function not implemented +Testing d3d11va_vld... no: Function not implemented +Testing cuda... no: Function not implemented +Testing 0rgb... ok +Testing rgb0... ok +Testing 0bgr... ok +Testing bgr0... ok +Testing yuv420p12be... no: Function not implemented +Testing yuv420p12le... ok +Testing yuv420p14be... no: Function not implemented +Testing yuv420p14le... ok +Testing yuv422p12be... no: Function not implemented +Testing yuv422p12le... ok +Testing yuv422p14be... no: Function not implemented +Testing yuv422p14le... ok +Testing yuv444p12be... no: Function not implemented +Testing yuv444p12le... ok +Testing yuv444p14be... no: Function not implemented +Testing yuv444p14le... ok +Testing gbrp12be... no: Function not implemented +Testing gbrp12le... ok +Testing gbrp14be... no: Function not implemented +Testing gbrp14le... ok +Testing yuvj411p... ok +Testing bayer_bggr8... no: Function not implemented +Testing bayer_rggb8... no: Function not implemented +Testing bayer_gbrg8... no: Function not implemented +Testing bayer_grbg8... no: Function not implemented +Testing bayer_bggr16le... no: Function not implemented +Testing bayer_bggr16be... no: Function not implemented +Testing bayer_rggb16le... no: Function not implemented +Testing bayer_rggb16be... no: Function not implemented +Testing bayer_gbrg16le... no: Function not implemented +Testing bayer_gbrg16be... no: Function not implemented +Testing bayer_grbg16le... no: Function not implemented +Testing bayer_grbg16be... no: Function not implemented +Testing yuv440p10le... ok +Testing yuv440p10be... no: Function not implemented +Testing yuv440p12le... ok +Testing yuv440p12be... no: Function not implemented +Testing ayuv64le... no: Function not implemented +Testing ayuv64be... no: Function not implemented +Testing videotoolbox_vld...no: Function not implemented +Testing p010le... ok +Testing p010be... no: Function not implemented +Testing gbrap12be... no: Function not implemented +Testing gbrap12le... ok +Testing gbrap10be... no: Function not implemented +Testing gbrap10le... ok +Testing mediacodec... no: Function not implemented +Testing gray12be... no: Function not implemented +Testing gray12le... ok +Testing gray10be... no: Function not implemented +Testing gray10le... ok +Testing p016le... ok +Testing p016be... no: Function not implemented +Testing d3d11... no: Function not implemented +Testing gray9be... no: Function not implemented +Testing gray9le... ok +Testing gbrpf32be... no: Function not implemented +Testing gbrpf32le... no: Function not implemented +Testing gbrapf32be... no: Function not implemented +Testing gbrapf32le... no: Function not implemented +Testing drm_prime... no: Function not implemented +Testing opencl... no: Function not implemented +Testing gray14be... no: Function not implemented +Testing gray14le... ok +Testing grayf32be... no: Function not implemented +Testing grayf32le... no: Function not implemented +Testing yuva422p12be... no: Function not implemented +Testing yuva422p12le... ok +Testing yuva444p12be... no: Function not implemented +Testing yuva444p12le... ok +Testing nv24... ok +Testing nv42... ok +Testing vulkan... no: Function not implemented +Testing y210be... no: Function not implemented +Testing y210le... no: Function not implemented +Testing x2rgb10le... no: Function not implemented +Testing x2rgb10be... no: Function not implemented +Testing x2bgr10le... no: Function not implemented +Testing x2bgr10be... no: Function not implemented +Testing p210be... no: Function not implemented +Testing p210le... ok +Testing p410be... no: Function not implemented +Testing p410le... ok +Testing p216be... no: Function not implemented +Testing p216le... ok +Testing p416be... no: Function not implemented +Testing p416le... ok +Testing vuya... ok +Testing rgbaf16be... no: Function not implemented +Testing rgbaf16le... no: Function not implemented +Testing vuyx... ok +Testing p012le... ok +Testing p012be... no: Function not implemented +Testing y212be... no: Function not implemented +Testing y212le... no: Function not implemented +Testing xv30be... no: Function not implemented +Testing xv30le... no: Function not implemented +Testing xv36be... no: Function not implemented +Testing xv36le... no: Function not implemented +Testing rgbf32be... no: Function not implemented +Testing rgbf32le... no: Function not implemented +Testing rgbaf32be... no: Function not implemented +Testing rgbaf32le... no: Function not implemented +Testing p212be... no: Function not implemented +Testing p212le... ok +Testing p412be... no: Function not implemented +Testing p412le... ok +Testing gbrap14be... no: Function not implemented +Testing gbrap14le... ok +Testing d3d12... no: Function not implemented +Testing ayuv... ok +Testing uyva... ok +Testing vyu444... ok +Testing v30xbe... no: Function not implemented +Testing v30xle... no: Function not implemented +Testing rgbf16be... no: Function not implemented +Testing rgbf16le... no: Function not implemented +Testing rgba128be... no: Function not implemented +Testing rgba128le... no: Function not implemented +Testing rgb96be... no: Function not implemented +Testing rgb96le... no: Function not implemented +Testing y216be... no: Function not implemented +Testing y216le... no: Function not implemented +Testing xv48be... no: Function not implemented +Testing xv48le... no: Function not implemented +Testing gbrpf16be... no: Function not implemented +Testing gbrpf16le... no: Function not implemented +Testing gbrapf16be... no: Function not implemented +Testing gbrapf16le... no: Function not implemented +Testing grayf16be... no: Function not implemented +Testing grayf16le... no: Function not implemented +Testing amf... no: Function not implemented +Testing gray32be... no: Function not implemented +Testing gray32le... no: Function not implemented +Testing yaf32be... no: Function not implemented +Testing yaf32le... no: Function not implemented +Testing yaf16be... no: Function not implemented +Testing yaf16le... no: Function not implemented +Testing gbrap32be... no: Function not implemented +Testing gbrap32le... no: Function not implemented +Testing yuv444p10msbbe... no: Function not implemented +Testing yuv444p10msble... ok +Testing yuv444p12msbbe... no: Function not implemented +Testing yuv444p12msble... ok +Testing gbrp10msbbe... no: Function not implemented +Testing gbrp10msble... ok +Testing gbrp12msbbe... no: Function not implemented +Testing gbrp12msble... ok +Testing ohcodec... no: Function not implemented +Testing cuarray... no: Function not implemented +half transparent red over transparent rgba by mask: 128 0 0 128 +half transparent red over transparent rgba by rectangle: 128 0 0 128 -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
