Commit 1794e927e7 for ffmpeg

commit 1794e927e70706582bcf1226e38ad7ffc2be1eaf
Author: Niklas Haas <git@haasn.dev>
Date:   Wed Jun 10 19:53:59 2026 +0200

    swscale/ops_optimizer: fold clears into linear ops

    This does not affect any current op lists, but slightly modifies the series
    of internal steps (clears are first folded into linear ops and then
    extracted again, rather than being commuted past reduced scaling ops).

    Sponsored-by: Sovereign Tech Fund
    Signed-off-by: Niklas Haas <git@haasn.dev>
    Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>

diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index 8a48c01fb1..fe621dd610 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -493,6 +493,24 @@ retry:
                 ff_sws_op_list_remove_at(ops, n + 1, 1);
                 goto retry;
             }
+
+            /* Fold into linear op */
+            if (next->op == SWS_OP_LINEAR) {
+                for (int j = 0; j < 4; j++) {
+                    if (!SWS_COMP_TEST(op->clear.mask, j))
+                        continue;
+
+                    const AVRational64 x = op->clear.value[j];
+                    for (int i = 0; i < 4; i++) {
+                        const AVRational64 kx = ff_mul_q64(next->lin.m[i][j], x);
+                        next->lin.m[i][4] = ff_add_q64(next->lin.m[i][4], kx);
+                        next->lin.m[i][j] = Q(0);
+                    }
+                }
+
+                ff_sws_op_list_remove_at(ops, n, 1);
+                goto retry;
+            }
             break;

         case SWS_OP_SWIZZLE: