Commit 32b9574ae4 for ffmpeg

commit 32b9574ae41e2821fab823f56dec45ba1244fc14
Author: romainhedouin <romain.hedouin@epitech.eu>
Date:   Fri Oct 16 11:22:25 2026 +0200

    avfilter/vf_drawbox: also hoist loop invariants in draw_region

    Same as the previous commit, for the planar YUV path. Hoisting only the
    alpha made 4:2:0 and 4:2:2 about 30% slower on arm64 with clang, so the
    colour and subsampling reads are hoisted as well.

    Output is identical: 1794 drawbox/drawgrid combinations, all 256 alpha
    values in 15 pixel formats, and fate-filter-drawbox pass.

    Full-frame fill, 1080p, arm64 with clang, CPU time: YUV 4:2:0 -13%,
    YUV 4:4:4 -23%. Not measured on x86.

    Found during a code review sweep of ffmpeg using an LLM.

    Signed-off-by: romainhedouin <romain.hedouin@epitech.eu>

diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index d44dc04171..deb117376b 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -134,6 +134,12 @@ static void draw_region(AVFrame *frame, DrawBoxContext *ctx, int left, int top,
             }
         }
     } else {
+        const double alpha = (double)ctx->yuv_color[A] / 255;
+        const int hsub = ctx->hsub;
+        const int yc = ctx->yuv_color[Y];
+        const int uc = ctx->yuv_color[U];
+        const int vc = ctx->yuv_color[V];
+
         for (y = top; y < down; y++) {
             ASSIGN_THREE_CHANNELS
             if (ctx->invert_color) {
@@ -142,12 +148,10 @@ static void draw_region(AVFrame *frame, DrawBoxContext *ctx, int left, int top,
                         row[0][x] = 0xff - row[0][x];
             } else {
                 for (x = left; x < right; x++) {
-                    double alpha = (double)ctx->yuv_color[A] / 255;
-
                     if (pixel_belongs_to_region(ctx, x, y)) {
-                        row[0][x             ] = (1 - alpha) * row[0][x             ] + alpha * ctx->yuv_color[Y];
-                        row[1][x >> ctx->hsub] = (1 - alpha) * row[1][x >> ctx->hsub] + alpha * ctx->yuv_color[U];
-                        row[2][x >> ctx->hsub] = (1 - alpha) * row[2][x >> ctx->hsub] + alpha * ctx->yuv_color[V];
+                        row[0][x        ] = (1 - alpha) * row[0][x        ] + alpha * yc;
+                        row[1][x >> hsub] = (1 - alpha) * row[1][x >> hsub] + alpha * uc;
+                        row[2][x >> hsub] = (1 - alpha) * row[2][x >> hsub] + alpha * vc;
                     }
                 }
             }