This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit e7965e84c50218c0ae6bb0183582ae03f5db5517 Author: Niklas Haas <[email protected]> AuthorDate: Wed Jan 21 14:36:26 2026 +0100 Commit: Niklas Haas <[email protected]> CommitDate: Thu Feb 19 19:44:46 2026 +0000 swscale/optimizer: fix unswizzle optimization The way this code was written relied on the implicit assumption that no other row was reading from the same column, which was true in practice so far but not necessarily true in general. Fix it by precomputing the nonzero component mask and then adding an explicit check. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas <[email protected]> --- libswscale/ops_optimizer.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c index 3bd2d12520..9aaca80408 100644 --- a/libswscale/ops_optimizer.c +++ b/libswscale/ops_optimizer.c @@ -245,21 +245,29 @@ static bool extract_swizzle(SwsLinearOp *op, SwsComps prev, SwsSwizzleOp *out_sw SwsSwizzleOp swiz = SWS_SWIZZLE(0, 1, 2, 3); SwsLinearOp c = *op; + /* Find non-zero coefficients in the main 4x4 matrix */ + uint32_t nonzero = 0; for (int i = 0; i < 4; i++) { - int idx = -1; for (int j = 0; j < 4; j++) { if (!c.m[i][j].num || (prev.flags[j] & SWS_COMP_ZERO)) continue; - if (idx >= 0) - return false; /* multiple inputs */ - idx = j; + nonzero |= SWS_MASK(i, j); } + } - if (idx >= 0 && idx != i) { - /* Move coefficient to the diagonal */ - c.m[i][i] = c.m[i][idx]; - c.m[i][idx] = Q(0); - swiz.in[i] = idx; + /* If a value is unique in its row and the target column is + * empty, move it there and update the input swizzle */ + for (int i = 0; i < 4; i++) { + if (nonzero & SWS_MASK_COL(i)) + continue; /* target column is not empty */ + for (int j = 0; j < 4; j++) { + if ((nonzero & SWS_MASK_ROW(i)) == SWS_MASK(i, j)) { + /* Move coefficient to the diagonal */ + c.m[i][i] = c.m[i][j]; + c.m[i][j] = Q(0); + swiz.in[i] = j; + break; + } } } _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
