Commit 6f7ca90701 for ffmpeg
commit 6f7ca90701ab4478ea42a7245ad88da45921e420
Author: romainhedouin <romain.hedouin@epitech.eu>
Date: Thu Oct 15 12:55:22 2026 +0200
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.
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];