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

Git pushed a commit to branch master
in repository ffmpeg.

commit 46d721a69aa17de5c526ff5b27c67988985683cf
Author:     Niklas Haas <[email protected]>
AuthorDate: Wed Jan 14 15:59:42 2026 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Thu Feb 19 19:44:46 2026 +0000

    swscale/optimizer: compress planar reads with unused planes
    
    After plane splitting, we can end up with a situation where a subpass wants
    to read only, say, the alpha plane. In this case, we should compress the
    planar read by instead swizzling the alpha plane into the correct place
    in the src plane order, and then reading only a single plane.
    
    Results in a bunch of benign diffs like:
    
     yuva444p -> ya8:
    -  [ u8 XXXX -> ++++] SWS_OP_READ         : 4 elem(s) planar >> 0
    -  [ u8 .XX. -> ++++] SWS_OP_CONVERT      : u8 -> f32
    -  [f32 .XX. -> .+++] SWS_OP_LINEAR       : luma [...]
    -  [f32 .XX. -> .+++] SWS_OP_DITHER       : 16x16 matrix + {0 3 2 5}
    -  [f32 .XX. -> .+++] SWS_OP_MAX          : {0 0 0 0} <= x
    -  [f32 .XX. -> .+++] SWS_OP_MIN          : x <= {255 _ _ 255}
    -  [f32 .XX. -> ++++] SWS_OP_CONVERT      : f32 -> u8
    -  [ u8 .XX. -> ++++] SWS_OP_SWIZZLE      : 0312
    -  [ u8 ..XX -> ++++] SWS_OP_WRITE        : 2 elem(s) packed >> 0
    +  [ u8 XXXX -> ++XX] SWS_OP_READ         : 2 elem(s) planar >> 0, via {0, 
3}
    +  [ u8 ..XX -> ++XX] SWS_OP_CONVERT      : u8 -> f32
    +  [f32 ..XX -> +XX+] SWS_OP_SWIZZLE      : 0321
    +  [f32 .XX. -> .XX+] SWS_OP_LINEAR       : luma [...]
    +  [f32 .XX. -> .XX+] SWS_OP_DITHER       : 16x16 matrix + {0 3 2 5}
    +  [f32 .XX. -> .XX+] SWS_OP_MAX          : {0 0 0 0} <= x
    +  [f32 .XX. -> .XX+] SWS_OP_MIN          : x <= {255 _ _ 255}
    +  [f32 .XX. -> +XX+] SWS_OP_CONVERT      : f32 -> u8
    +  [ u8 .XX. -> ++XX] SWS_OP_SWIZZLE      : 0312
    +  [ u8 ..XX -> ++XX] SWS_OP_WRITE        : 2 elem(s) packed >> 0
    
    This may seem noisy, but really is mostly a result of the fact that the 
unused
    middle components are now marked as garbage instead of as valid data.
    
    Sponsored-by: Sovereign Tech Fund
    Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops_optimizer.c  | 28 ++++++++++++++++++++++------
 tests/ref/fate/sws-ops-list |  2 +-
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index 2abaaf37d9..d0f763f989 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -299,13 +299,29 @@ retry:
 
         switch (op->op) {
         case SWS_OP_READ:
-            /* Skip reading extra unneeded components */
+            /* "Compress" planar reads where not all components are needed */
             if (!op->rw.packed) {
-                int needed = op->rw.elems;
-                while (needed > 0 && next->comps.unused[needed - 1])
-                    needed--;
-                if (op->rw.elems != needed) {
-                    op->rw.elems = needed;
+                SwsSwizzleOp swiz = SWS_SWIZZLE(0, 1, 2, 3);
+                int nb_planes = 0;
+                for (int i = 0; i < op->rw.elems; i++) {
+                    if (next->comps.unused[i]) {
+                        swiz.in[i] = 3 - (i - nb_planes); /* map to unused 
plane */
+                        continue;
+                    }
+
+                    const int idx = nb_planes++;
+                    av_assert1(idx <= i);
+                    ops->order_src.in[idx] = ops->order_src.in[i];
+                    swiz.in[i] = idx;
+                }
+
+                if (nb_planes < op->rw.elems) {
+                    op->rw.elems = nb_planes;
+                    RET(ff_sws_op_list_insert_at(ops, n + 1, &(SwsOp) {
+                        .op = SWS_OP_SWIZZLE,
+                        .type = op->type,
+                        .swizzle = swiz,
+                    }));
                     goto retry;
                 }
             }
diff --git a/tests/ref/fate/sws-ops-list b/tests/ref/fate/sws-ops-list
index 6111cc4cbd..af3cf2f4e9 100644
--- a/tests/ref/fate/sws-ops-list
+++ b/tests/ref/fate/sws-ops-list
@@ -1 +1 @@
-1c8369d53a092dd41f88f333f6a8e426
+3505d38dc669faf6f14036516b6caf61

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

Reply via email to