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

Git pushed a commit to branch master
in repository ffmpeg.

commit 18edb246c80902e192c464fb9b7d6b15d9c11557
Author:     Niklas Haas <[email protected]>
AuthorDate: Mon Dec 8 13:53:38 2025 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Mon Dec 15 14:31:58 2025 +0000

    swscale/ops_optimizer: correctly commute swizzles with dither ops
    
    This requires updating the order of the dither matrix offsets as well. In
    particular, this can only be done cleanly if the dither matrix offsets are
    compatible between duplicated channels; but this should be guaranteed after
    the previous commits.
    
    As a side note, this also fixes a bug where we pushed SWS_OP_SWIZZLE past
    SWS_OP_DITHER even for very low bit depth output (e.g. rgb4), which led to
    a big loss in accuracy due to loss of per-channel dither noise.
    
    Improves loss of e.g. gray -> rgb444 from 0.00358659 to 0.00261414,
    now beating legacy swscale in these cases as well.
---
 libswscale/ops_optimizer.c  | 15 ++++++++++++++-
 tests/ref/fate/sws-ops-list |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index e1b52da374..f317a84f9a 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -88,7 +88,6 @@ static bool op_commute_swizzle(SwsOp *op, SwsOp *next)
     case SWS_OP_SWAP_BYTES:
     case SWS_OP_LSHIFT:
     case SWS_OP_RSHIFT:
-    case SWS_OP_DITHER:
     case SWS_OP_SCALE:
         return true;
 
@@ -116,6 +115,20 @@ static bool op_commute_swizzle(SwsOp *op, SwsOp *next)
         return true;
     }
 
+    case SWS_OP_DITHER: {
+        const SwsDitherOp d = next->dither;
+        for (int i = 0; i < 4; i++) {
+            if (next->comps.unused[i])
+                continue;
+            const int j = op->swizzle.in[i];
+            if (seen[j] && next->dither.y_offset[j] != d.y_offset[i])
+                return false;
+            next->dither.y_offset[j] = d.y_offset[i];
+            seen[j] = true;
+        }
+        return true;
+    }
+
     case SWS_OP_INVALID:
     case SWS_OP_READ:
     case SWS_OP_WRITE:
diff --git a/tests/ref/fate/sws-ops-list b/tests/ref/fate/sws-ops-list
index bff44d5446..dbcad4052b 100644
--- a/tests/ref/fate/sws-ops-list
+++ b/tests/ref/fate/sws-ops-list
@@ -1 +1 @@
-0c7f5082617b0b4b83111b67bec74f2d
+708f10e4de79450729ab2120e4e44ec9

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

Reply via email to