PR #25090 opened by romainhedouin URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25090 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25090.patch
alpha only depends on the box colour, so compute it once per call instead of for every pixel. The output is unchanged. About 10-25% less CPU on full-frame boxes and grids (rgb24/rgba, 1080p, arm64). Small boxes are not affected. Found during a code review sweep of ffmpeg using an LLM. <!-- If this PR requires new FATE test samples, attach them to the PR and list their target paths below (relative to the fate-suite root). Attached filenames must match the sample's filename: ```fate-samples # e.g. vorbis/new-sample.ogg ``` --> >From b388700d02fddc26e75466f8e98068f3a19a900d Mon Sep 17 00:00:00 2001 From: romainhedouin <[email protected]> Date: Thu, 15 Oct 2026 12:55:22 +0200 Subject: [PATCH] avfilter/vf_drawbox: compute alpha once in draw_region_rgb_packed alpha only depends on the box colour, so compute it once per call instead of for every pixel. The output is unchanged. About 10-25% less CPU on full-frame boxes and grids (rgb24/rgba, 1080p, arm64). Small boxes are not affected. Found during a code review sweep of ffmpeg using an LLM. --- libavfilter/vf_drawbox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index ec409603d3..d44dc04171 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -192,6 +192,8 @@ static void draw_region_rgb_packed(AVFrame *frame, DrawBoxContext *ctx, int left } } } else { + const float alpha = (float)ctx->rgba_color[A] / 255.f; + for (int y = top; y < down; y++) { ASSIGN_THREE_CHANNELS_PACKED if (ctx->invert_color) { @@ -203,8 +205,6 @@ static void draw_region_rgb_packed(AVFrame *frame, DrawBoxContext *ctx, int left } } else { for (int x = left; x < right; x++) { - float alpha = (float)ctx->rgba_color[A] / 255.f; - if (pixel_belongs_to_region(ctx, x, y)) { row[0][x*C] = (1.f - alpha) * row[0][x*C] + alpha * ctx->rgba_color[R]; row[1][x*C] = (1.f - alpha) * row[1][x*C] + alpha * ctx->rgba_color[G]; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
