Commit 2171f9836c for ffmpeg

commit 2171f9836cc2edf8951bea396a285ba922f6bec5
Author: Niklas Haas <git@haasn.dev>
Date:   Mon Oct 19 15:44:34 2026 +0200

    swscale/ops: add ff_sws_op_prev/next() helpers

    Signed-off-by: Niklas Haas <git@haasn.dev>

diff --git a/libswscale/ops.c b/libswscale/ops.c
index a66832f3e9..caf933bd58 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -143,6 +143,31 @@ int ff_sws_rw_op_planes(const SwsOp *op)
     return 0;
 }

+static inline int op_index(const SwsOp *op)
+{
+    SwsOpList *ops = op->ops;
+    av_assert1(op >= ops->ops && op < ops->ops + ops->num_ops);
+    return op - ops->ops;
+}
+
+const SwsOp *ff_sws_op_prev(const SwsOp *op)
+{
+    if (!op)
+        return NULL;
+    SwsOpList *ops = op->ops;
+    const int idx = op_index(op);
+    return idx > 0 ? &ops->ops[idx - 1] : NULL;
+}
+
+const SwsOp *ff_sws_op_next(const SwsOp *op)
+{
+    if (!op)
+        return NULL;
+    SwsOpList *ops = op->ops;
+    const int idx = op_index(op);
+    return idx < ops->num_ops - 1 ? &ops->ops[idx + 1] : NULL;
+}
+
 /* biased towards `a` */
 static AVRational64 av_min_q64(AVRational64 a, AVRational64 b)
 {
diff --git a/libswscale/ops.h b/libswscale/ops.h
index aad48660b3..bfb5085ae5 100644
--- a/libswscale/ops.h
+++ b/libswscale/ops.h
@@ -306,6 +306,12 @@ void ff_sws_op_uninit(SwsOp *op);
  */
 void ff_sws_apply_op_q(const SwsOp *op, AVRational64 x[4]);

+/**
+ * Return the previous/next operation in the list, or NULL if there is none.
+ */
+const SwsOp *ff_sws_op_prev(const SwsOp *op);
+const SwsOp *ff_sws_op_next(const SwsOp *op);
+
 /**
  * Helper struct for representing a list of operations.
  */
diff --git a/libswscale/ops_dispatch.c b/libswscale/ops_dispatch.c
index d2669d6cbd..2268100154 100644
--- a/libswscale/ops_dispatch.c
+++ b/libswscale/ops_dispatch.c
@@ -479,7 +479,7 @@ static void op_list_get_plane_copy(const SwsOpList *ops, SwsPass *pass)
         read->rw.frac != write->rw.frac)
         return; /* only regular planes can be directly ref'd */

-    const SwsOp *prev = &ops->ops[ops->num_ops - 2];
+    const SwsOp *prev = ff_sws_op_prev(write);
     int *plane_copy = pass->output->plane_copy;
     for (int i = 0; i < write->rw.elems; i++) {
         SwsCompFlags flags = prev->outputs[i].flags;
@@ -729,7 +729,8 @@ static int compile_subpass(const CompileArgs *args, SwsOpList **pops,
         /* Split off copied and constant planes into a separate subpass,
          * since these are likely to be handled by the memcpy backend */
         av_assert0(ops->num_ops >= 2);
-        const SwsOp *prev = &ops->ops[ops->num_ops - 2];
+        const SwsOp *write = ff_sws_op_list_output(ops);
+        const SwsOp *prev = ff_sws_op_prev(write);
         SwsCompMask planes = plane_mask_flags(prev, SWS_COMP_COPY | SWS_COMP_CONST);
         RET(ff_sws_op_list_split_planes(ops, &rest, planes));
         if (rest) {