22 Commits

Author SHA1 Message Date
Niklas Haas
df4fe85ae3 swscale/ops_chain: replace SwsOpEntry.unused by SwsCompMask
Needed to allow us to phase out SwsComps.unused altogether.

It's worth pointing out the change in semantics; while unused tracks the
unused *input* components, the mask is defined as representing the
computed *output* components.

This is 90% the same, expect for read/write, pack/unpack, and clear; which
are the only operations that can be used to change the number of components.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-16 23:25:10 +02:00
Niklas Haas
6a83e15392 swscale/ops_chain: simplify SwsClearOp checking
Since this now has an explicit mask, we can just check that directly, instead
of relying on the unused comps hack/trick.

Additionally, this also allows us to distinguish between fixed value and
arbitrary value clears by just having the SwsOpEntry contain NAN values iff
they support any clear value.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-16 23:24:22 +02:00
Niklas Haas
32ba5c13de swscale/ops_chain: split generic setup helpers into op-specific helpers
This has the side benefit of not relying on the q2pixel macro to avoid division
by zero, since we can now explicitly avoid operating on undefined clear values.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-02 11:48:15 +00:00
Niklas Haas
50793bc9bd swscale/ops_chain: remove unused helper function
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-02 11:48:15 +00:00
Niklas Haas
3f39783337 swscale/ops_chain: simplify ff_sws_compile_op_tables() with int index
Instead of this needlessly complicated dance of allocating on-stack copies
of SwsOpList only to iterate with AVERROR(EAGAIN).

This was originally thought to be useful for compiling multiple ops at once,
but even that can be solved in easier ways.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-29 12:13:40 +02:00
Niklas Haas
4ff32b6e86 swscale/ops_chain: add optional check() call to SwsOpEntry
Allows implementations to implement more advanced logic to determine if an
operation is compatible or not.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-28 18:50:14 +01:00
Niklas Haas
1a8c3d522e swscale/ops_backend: add support for SWS_OP_FILTER_H
Naive scalar loop to serve mainly as a reference for the asm backends.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-28 18:50:14 +01:00
Niklas Haas
8e3eacd7ad swscale/ops_chain: allow implementations to expose over_read/write
And plumb it all the way through to the SwsCompiledOp. This is cleaner than
setting up this metadata up-front in x86/ops.c; and more importantly, it
allows us to determine the amount of over-read programmatically during ops
setup.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
3aef0213e7 swscale/ops_chain: add SwsContext to SwsImplParams
Mainly so that implementations can consult sws->flags, to e.g. decide
whether the kernel needs to be bit-exact.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
9c6638b179 swscale/ops_chain: add SwsOpTable to SwsImplParams
Mainly so setup functions can look at table->block_size, and perhaps
the table flags, as well as anything else we may add in the future.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
ef114cedef swscale/ops_chain: refactor setup() signature
This is basically a cosmetic commit that groups all of the parameters to
setup() into a single struct, as well as the return type. This gives the
immediate benefit of freeing up 8 bytes per op table entry, though the
main motivation will come in the following commits.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Martin Storsjö
ac4d50cb26 swscale/ops_chain: Make ff_op_priv_free clear the freed pointer 2026-03-16 20:31:12 +00:00
Martin Storsjö
e07daf85a4 swscale/ops_chain: Don't pass an aligned union as parameter by value
Passing a struct/union by value can generally be inefficient.
Additionally, when the struct/union is declared to be aligned,
whether it really stays aligned when passed as a parameter by
value is unclear.

This fixes build errors like this, with MSVC targeting 32 bit ARM:

    libswscale/ops_chain.h(91): error C2719: 'unnamed-parameter': formal parameter with requested alignment of 16 won't be aligned
2026-03-16 20:31:12 +00:00
Niklas Haas
4e63dbeb6d swscale/ops_chain: add more integer types to SwsOpPriv
In particular, I need i32, but the others are also reasonable additions.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-12 21:02:48 +00:00
Niklas Haas
f535212a2c swscale/ops_chain: allow free callback to take SwsOpPriv
I mainly want to be able to store two pointers side-by-side.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-12 21:02:48 +00:00
Niklas Haas
ce096aa4ee swscale/x86/ops: add support for optional dither indices
Instead of defining multiple patterns for the dither ops, just define a
single generic function that branches internally. The branch is well-predicted
and ridiculously cheap. At least on my end, within margin of error.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 13:09:14 +00:00
Niklas Haas
8b346363aa swscale/ops_backend: implement support for optional dither indices
If you place the branch inside the loop, gcc at least reverts back to scalar
code, so better to just split up and guard the entire loop.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 13:09:14 +00:00
Niklas Haas
3a5b1d762f swscale/ops_chain: add ability to match fixed scale factor
This is useful especially for the special case of scaling by common
not-quite-power-of-two constants like 255 or 1023.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 10:15:52 +00:00
Niklas Haas
94777ed2eb swscale/ops_chain: fix comment 2025-12-20 13:52:45 +00:00
Kacper Michajłow
66faef3dbe swscale/ops_chain: add type removed ff_sws_op_chain_free_cb
to avoid pointer casting and UB of calling function with different
pointer type.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-09-13 18:14:02 +02:00
Martin Storsjö
a3360c0eaf swscale: Don't pass a concrete SwsOpPriv as parameter
This fixes the following compiler error, if compiling with MSVC
for ARM (32 bit):

    src/libswscale/ops_chain.c(48): error C2719: 'priv': formal parameter with requested alignment of 16 won't be aligned

This change shouldn't affect the performance of this operation
(which in itself probably isn't relevant); instead of copying the
contents of the SwsOpPriv struct from the stack as parameter,
it gets copied straight from the caller function's stack frame
instead.

Separately from this issue, MSVC 17.8 and 17.9 end up in an
internal compiler error when compiling libswscale/ops.c, but
older and newer versions do compile it successfully.
2025-09-03 20:18:03 +00:00
Niklas Haas
99d73064f5 swscale/ops_chain: add internal abstraction for kernel linking
See doc/swscale-v2.txt for design details.
2025-09-01 19:28:36 +02:00