This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 4d7b1c3685038321975d575fca1e498183d69139
Author:     Niklas Haas <[email protected]>
AuthorDate: Thu Feb 26 19:13:13 2026 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Fri Feb 27 16:18:34 2026 +0000

    swscale/graph: move frame->field init logic to SwsGraph
    
    And have ff_sws_graph_run() just take a bare AVFrame. This will help with
    an upcoming change, aside from being a bit friendlier towards API users
    in general.
    
    Sponsored-by: Sovereign Tech Fund
    Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/graph.c   | 48 +++++++++++++++++++++++++++++++++++++++++-------
 libswscale/graph.h   |  5 +++--
 libswscale/swscale.c | 38 +-------------------------------------
 3 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/libswscale/graph.c b/libswscale/graph.c
index 97cd6adbb2..5469012f37 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -869,18 +869,52 @@ void ff_sws_graph_update_metadata(SwsGraph *graph, const 
SwsColor *color)
     ff_color_update_dynamic(&graph->src.color, color);
 }
 
-void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg 
*input)
+static SwsImg get_field(const AVFrame *frame, int field)
 {
-    av_assert0(output->fmt == graph->dst.hw_format ||
-               output->fmt == graph->dst.format);
-    av_assert0(input->fmt  == graph->src.hw_format ||
-               input->fmt  == graph->src.format);
+    SwsImg img = {0};
+
+    img.frame_ptr = frame;
+    img.fmt = frame->format;
+    for (int i = 0; i < 4; i++) {
+        img.data[i]     = frame->data[i];
+        img.linesize[i] = frame->linesize[i];
+    }
+
+    if (!(frame->flags & AV_FRAME_FLAG_INTERLACED)) {
+        av_assert1(!field);
+        return img;
+    }
+
+    if (field == FIELD_BOTTOM) {
+        /* Odd rows, offset by one line */
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+        for (int i = 0; i < 4; i++) {
+            if (img.data[i])
+                img.data[i] += img.linesize[i];
+            if (desc->flags & AV_PIX_FMT_FLAG_PAL)
+                break;
+        }
+    }
+
+    /* Take only every second line */
+    for (int i = 0; i < 4; i++)
+        img.linesize[i] <<= 1;
+
+    return img;
+}
+
+void ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst, const AVFrame *src)
+{
+    av_assert0(dst->format == graph->dst.hw_format || dst->format == 
graph->dst.format);
+    av_assert0(src->format == graph->src.hw_format || src->format == 
graph->src.format);
+    SwsImg input  = get_field(src, graph->field);
+    SwsImg output = get_field(dst, graph->field);
 
     for (int i = 0; i < graph->num_passes; i++) {
         const SwsPass *pass = graph->passes[i];
         graph->exec.pass   = pass;
-        graph->exec.input  = pass->input ? pass->input->output->img : *input;
-        graph->exec.output = pass->output->frame ? pass->output->img : *output;
+        graph->exec.input  = pass->input ? pass->input->output->img : input;
+        graph->exec.output = pass->output->frame ? pass->output->img : output;
         if (pass->setup)
             pass->setup(&graph->exec.output, &graph->exec.input, pass);
         avpriv_slicethread_execute(graph->slicethread, pass->num_slices, 0);
diff --git a/libswscale/graph.h b/libswscale/graph.h
index e231938e72..6d3db640fd 100644
--- a/libswscale/graph.h
+++ b/libswscale/graph.h
@@ -189,8 +189,9 @@ int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat 
*dst, const SwsFormat *
                         int field, SwsGraph **graph);
 
 /**
- * Dispatch the filter graph on a single field. Internally threaded.
+ * Dispatch the filter graph on a single field of the given frames. Internally
+ * threaded.
  */
-void ff_sws_graph_run(SwsGraph *graph, const SwsImg *output, const SwsImg 
*input);
+void ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst, const AVFrame *src);
 
 #endif /* SWSCALE_GRAPH_H */
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 5dbd93e0a2..b04df78a5d 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1321,40 +1321,6 @@ int sws_receive_slice(SwsContext *sws, unsigned int 
slice_start,
                           dst, c->frame_dst->linesize, slice_start, 
slice_height);
 }
 
-static SwsImg get_frame_img(const AVFrame *frame, int field)
-{
-    SwsImg img = {0};
-
-    img.frame_ptr = frame;
-    img.fmt = frame->format;
-    for (int i = 0; i < 4; i++) {
-        img.data[i]     = frame->data[i];
-        img.linesize[i] = frame->linesize[i];
-    }
-
-    if (!(frame->flags & AV_FRAME_FLAG_INTERLACED)) {
-        av_assert1(!field);
-        return img;
-    }
-
-    if (field == FIELD_BOTTOM) {
-        /* Odd rows, offset by one line */
-        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
-        for (int i = 0; i < 4; i++) {
-            if (img.data[i])
-                img.data[i] += img.linesize[i];
-            if (desc->flags & AV_PIX_FMT_FLAG_PAL)
-                break;
-        }
-    }
-
-    /* Take only every second line */
-    for (int i = 0; i < 4; i++)
-        img.linesize[i] <<= 1;
-
-    return img;
-}
-
 /* Subset of av_frame_ref() that only references (video) data buffers */
 static int frame_ref(AVFrame *dst, const AVFrame *src)
 {
@@ -1419,9 +1385,7 @@ int sws_scale_frame(SwsContext *sws, AVFrame *dst, const 
AVFrame *src)
 
         for (int field = 0; field < 2; field++) {
             SwsGraph *graph = c->graph[field];
-            SwsImg input  = get_frame_img(src, field);
-            SwsImg output = get_frame_img(dst, field);
-            ff_sws_graph_run(graph, &output, &input);
+            ff_sws_graph_run(graph, dst, src);
             if (!graph->dst.interlaced)
                 break;
         }

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to