Commit graph

3030 commits

Author SHA1 Message Date
Michael Niedermayer
c1263a3dd9
Bump versions for master after release/8.1
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 02:31:23 +01:00
Michael Niedermayer
67c886222f
Bump versions for release/8.1
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 02:29:20 +01:00
Andreas Rheinhardt
38c578b909 swscale_x86/swscale_template: Remove unused macros
WRITEBGR24MMX is unused after a05f22eaf3.

Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-07 18:06:43 +01:00
James Almer
6dd446918a swscale/utils: don't abort early in sws_freeContext() for non legacy API
There are some buffers still allocated even with it.
Fixes memleaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-07 15:46:23 +00:00
James Almer
9f0441a774 swscale/x86/input: don't overread input in RGB24_TO_UV_FN
Fixes a 4 byte overread after 846823b174 removed padding

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-06 23:13:45 -03:00
Michael Niedermayer
1e63151355
swscale/output: Fix integer overflow in alpha in yuv2rgba64_1_c_template()
Fixes: signed integer overflow: -1548257 * 2048 cannot be represented in type 'int'
Fixes: #21592

Found-by: HAORAN FANG
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-06 23:09:44 +01:00
Michael Niedermayer
946ce12e1c
swscale/utils: Check *Inc
Fixes: signed integer overflow: -2147483648 - 65536 cannot be represented in type 'int'
Fixes: #21588

Found-by: HAORAN FANG
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-06 23:09:44 +01:00
Michael Niedermayer
a59180022a
swscale/output: Fixes integer overflow in yuv2planeX_8_c
Fixes: integer overflow (does not replicate, but looks like it should overflow with some craftet parameters)
Fixes: #21584

Found-by: HAORAN FANG
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-06 23:09:26 +01:00
Michael Niedermayer
dc9bf66796
swscale/utils: initialize chroma when luma switched to cascade
When luma init switched to cascade the chroma init was skiped

Fixes: NULL pointer dereference
Fixes: #21583

Found-by: HAORAN FANG
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-06 23:09:26 +01:00
Niklas Haas
47f89ea88b swscale: explicitly track if a context is "legacy" or not
The legacy API is defined by sws_init_context(), sws_scale() etc., whereas
the "modern" API is defined by just using sws_scale_frame() without prior
init call.

This int allows us to cleanly distinguish the type of context, paving the
way for some minor refactoring.

As an immediate benefit, we now gain a bunch of explict error checks to
ensure the API is used correctly (i.e. sws_scale() not called before
sws_init_context()).

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-06 19:06:33 +01:00
Niklas Haas
1c2a300f66 swscale/graph: remove pointless helper
Basically identical to ff_sws_graph_add_pass() after the previous commit.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
d9e594ca96 swscale/graph: have ff_sws_graph_add_pass() return an error code
This allows distinguishing between different types of failure, e.g.
AVERROR(EINVAL) on invalid pass dimensions.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
4b5122bfb2 swscale/ops_dispatch: move on-stack mutation to ops backends
And move the remainder printing there as well.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
b4bcb00cd3 swscale/ops: add and use ff_sws_op_list_input/output()
Makes various pieces of code that expect to get a SWS_OP_READ more robust,
and also allows us to generalize to introduce more input op types in the
future (in particular, I am looking ahead towards filter ops).

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
cc334a223e swscale/ops_backend: move static table out of function body
Ditto for x86.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
68f3886460 swscale/ops_dispatch: split off compile/dispatch code from ops.c
This code is self-contained and logically distinct from the ops-related
helpers in ops.c, so it belongs in its own file.

Purely cosmetic; no functional change.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
4178c4d430 swscale/ops: remove unneeded macro
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
5384908e56 swscale/ops: move pass compilation logic to helper function
Purely cosmetic.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Ramiro Polla
493dfc356f swscale/swscale_internal: fix typos in flag names 2026-03-05 20:38:55 +01:00
Niklas Haas
cef2fbfd4b swscale/vulkan: fix include order (cosmetic)
Non-local includes before local includes.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-04 12:04:12 +01:00
Niklas Haas
1512e52cb4 swscale: switch to refstruct for hw_priv
This is a bit more forward-facing than a bare allocation, and importantly,
allows the `swscale/utils.c` code to remain agnostic about how to correctly
uninit this struct.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-04 12:04:09 +01:00
Niklas Haas
5b39be1f0a swscale: fix build on --disable-unstable
By excluding the Vulkan makefile entirely when --disable-unstable is passed.
This also correctly avoids compiling e.g. unused GLSL compilers.

Fixes: #22295
See-Also: #22366

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-04 11:53:10 +01:00
David Christle
2c7fe8d8ad swscale/aarch64: add NEON rgb32tobgr24 and rgb24tobgr32 conversions
Add NEON alpha drop/insert using ldp+tbl+stp instead of ld4/st3 and
ld3/st4 structure operations. Both use a 2-register sliding-window
tbl with post-indexed addressing. Instruction scheduling targets
narrow in-order cores (A55) while remaining neutral on wide OoO.

Scalar tails use coalesced loads/stores (ldr+strh+lsr+strb for alpha
drop, ldrh+ldrb+orr+str for alpha insert) to reduce per-pixel
instruction count. Independent instructions placed between loads and
dependent operations to fill load-use latency on in-order cores.

checkasm --bench on Apple M3 Max (decicycles, 1920px):
  rgb32tobgr24_c:    114.4 ( 1.00x)
  rgb32tobgr24_neon:  64.3 ( 1.78x)
  rgb24tobgr32_c:    128.9 ( 1.00x)
  rgb24tobgr32_neon:  80.9 ( 1.59x)

C baseline is clang auto-vectorized; speedup is over compiler NEON.

Signed-off-by: David Christle <dev@christle.is>
2026-03-04 10:30:08 +00:00
David Christle
ddd720ae61 swscale/aarch64: add NEON rgb24tobgr24 byte-swap
Add a NEON rgb24tobgr24 using ld3/st3 to swap R and B channels in
packed 24bpp RGB buffers. Handles all input sizes with a 16-pixel
NEON fast path, 8-pixel NEON cleanup, and scalar tail.

checkasm --bench on Apple M3 Max (1920*3 = 5760 bytes):
  rgb24tobgr24_c:    722.0 ( 1.00x)
  rgb24tobgr24_neon:  94.9 ( 7.61x)

Signed-off-by: David Christle <dev@christle.is>
2026-03-04 10:30:08 +00:00
Niklas Haas
0540b42657 swscale/graph: correctly handle single threaded mode
The code was evidently designed at one point in time to support "direct"
execution (not via a thread pool) for num_threads == 1, but this was never
implemented.

As a side benefit, reduces context creation overhead in single threaded
mode (relevant e.g. inside the libswscale self test), due to not needing to
spawn and destroy several thousand worker threads.

Co-authored-by: Ramiro Polla <ramiro.polla@gmail.com>
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-03 23:13:41 +00:00
AnandajithS
04fe98482a libswscale/utils: prevent division by zero for chroma width 8 2026-03-03 17:38:01 +00:00
David Christle
7fab0becab swscale/aarch64: add NEON YUV420P/YUV422P/YUVA420P to RGB conversion
Add ARM64 NEON-accelerated unscaled YUV-to-RGB conversion for planar
YUV input formats. This extends the existing NV12/NV21 NEON paths with
YUV420P, YUV422P, and YUVA420P support for all packed RGB output
formats (ARGB, RGBA, ABGR, BGRA, RGB24, BGR24) and planar GBRP.

Register with ff_yuv2rgb_init_aarch64() to also cover the scaled path.

checkasm: all 42 sw_yuv2rgb tests pass.
Speedup vs C at 1920px width (Apple M3 Max, avg of 20 runs):
  yuv420p->rgb24:   4.3x    yuv420p->argb:   3.1x
  yuv422p->rgb24:   5.5x    yuv422p->argb:   4.1x
  yuva420p->argb:   3.5x    yuva420p->rgba:  3.5x

Signed-off-by: David Christle <dev@christle.is>
2026-03-02 13:14:07 +00:00
David Christle
8e591af32b swscale/loongarch: fix LASX YUV2RGB residual for multi-row slices
The res variable (pixel residual count for widths not divisible by 16)
is computed once before the row loop, but DEALYUV2RGBLINERES and
DEALYUV2RGBLINERES32 destructively subtract 8 from it inside the loop
body. When srcSliceH > 2, subsequent row pairs get an incorrect
residual count, producing wrong output for the tail pixels.

Fix by recomputing res from the constant c->opts.dst_w at the top of
each row-pair iteration.

Signed-off-by: David Christle <dev@christle.is>
2026-03-02 13:14:07 +00:00
Andreas Rheinhardt
862338fe31 swscale/rgb2rgb: Remove set-but-unused functions
yuy2toyv12, vu9_to_vu12 and yvu9_to_yuy2 are unused. Removing
them saved 7808B of .text and 102B of .text.unlikely
as well as 24B of .bss here.
Thanks to James Almer for pointing out that yuy2toyv12 is unused.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-01 23:45:11 +00:00
Andreas Rheinhardt
ecd11abcc9 swscale/rgb2rgb_template: Remove unused uyvytoyv12_c()
Added in 81c0590e6c,
but it seems to have always been unused.
See also 5421dee0e7.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-01 23:45:11 +00:00
Niklas Haas
5375cfd9c7 swscale/vulkan/ops: fix typo
Checks src.interlaced twice.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-01 21:57:53 +00:00
Niklas Haas
b2266d6656 swscale/graph: correctly adjust field height for interlaced frames
This is a pre-existing bug from 67f3627267.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-01 21:57:53 +00:00
Niklas Haas
02e4b45f7f swscale/graph: reintroduce SwsFrame
AVFrame just really doesn't have the semantics we want. However, there a
tangible benefit to having SwsFrame act as a carbon copy of a (subset of)
AVFrame.

This partially reverts commit 67f3627267.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-01 21:57:53 +00:00
Andreas Rheinhardt
f570fa787a swscale/swscale_internal: Move altivec parts to ppc/
Up until now, several altivec-specific fields are directly
put into SwsInternal #if HAVE_ALTIVEC is true. These fields
are of altivec-specific vector types and therefore
require altivec specific headers to be included.

Unfortunately, said altivec specific headers redefine
bool in a manner that is incompatible with stdbool.
swscale/ops.h uses bool and this led graph.c and ops.c
to disagree about the layout of structures from ops.h,
leading to heap corruption [1], [2] in the sws-unscaled
FATE test.

Fix this by moving the altivec-specific parts out of SwsInternal
and into a structure that extends SwsInternal and is allocated
jointly with it. Said structure is local to yuv2rgb_altivec.c,
because this is the only file accessing said fields. Should
more files need them, an altivec-specific swscale header would
need to be added.

Thanks to jfiusdq <jfiusdq@proton.me> for analyzing the issue.

[1]: https://fate.ffmpeg.org/report.cgi?slot=ppc64-linux-gcc-14.3-asan&time=20260224065643
[2]: https://fate.ffmpeg.org/report.cgi?slot=ppc64-linux-gcc-14.3&time=20260224051615

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-02-28 09:56:01 +01:00
Andreas Rheinhardt
76cb5691e8 swscale/utils: Move altivec init/free code to yuv2rgb_altivec.c
This is in preparation for removing the util_altivec.h inclusion
in swscale_internal.h, which causes problems (on PPC) because
it redefines bool to something different from stdbool.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-02-28 09:56:01 +01:00
Ramiro Polla
23bb7c3907 swscale/ops_backend: mark unreachable branch
The pixel format for the process loops have already been checked at
this point to be valid.

The switch added in e4abfb8e51 returns AVERROR(EINVAL) in the default
case without calling ff_sws_op_chain_free(chain), but there's no need
to free it since we mark this branch as unreachable.
2026-02-27 16:44:19 +00:00
Niklas Haas
67f3627267 swscale/graph: nuke SwsImg
This has now become fully redundant with AVFrame, especially since the
existence of SwsPassBuffer. Delete it, simplifying a lot of things and
avoiding reinventing the wheel everywhere.

Also generally reduces overhead, since there is less redundant copying
going on.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
4d7b1c3685 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 <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
846823b174 swscale/graph: don't pointlessly align data buffers
Since d67d81a374, enabling asm explicitly requires aligned malloc,
so this FFALIGN accomplishes nothing.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
5121665463 swscale/graph: use AVFrame to track internal allocation
This commit replaces the AVBufferRef inside SwsPassBuffer by an AVFrame, in
anticipation of the SwsImg removal.

Incidentally, we could also now just use av_frame_get_buffer() here, but
at the cost of breaking the 1:1 relationship between planes and buffers,
which is required for per-plane refcopies.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
e9d1ed3fdc swscale/graph: avoid stack copies of SwsImg
In the process of nuking this abstraction in favor of AVFrame.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
d89765eb28 swscale/graph: simplify output buffer management
This function was originally written to support the use case of e.g.
partially allocated planes that implicitly reference the original input
image, but I've decided that this is stupid and doesn't currently work
anyways.

Plus, I have plans to kill SwsImg, so we need to simplify this mess.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
363779a4bb swscale/ops: don't set src/dst_frame_ptr in op_pass_run()
Already set by setup().

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
62dc591a80 swscale/ops: correctly shift pointers for last row handling
The current logic didn't take into account the possible plane shift. Just
re-compute the correctly shifted pointers using the row position.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
bca806d4f9 swscale/ops: avoid stack copies of SwsImg
Instead, precompute the correctly swizzled data and stride in setup()
and just reference the SwsOpExec fields directly.

To avoid the stack copies in handle_tail() we can introduce a temporary
array to hold just the pointers.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
79334c8ca1 swscale/ops: add subsampling shift to SwsOpExec
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
3c03048837 swscale/x86/ops: fix MSVC compiler error
src/libswscale/x86/ops.c(534): error C2099: initializer is not a constant
src/libswscale/x86/ops.c(535): error C2099: initializer is not a constant
src/libswscale/x86/ops.c(536): error C2099: initializer is not a constant
src/libswscale/x86/ops.c(537): error C2099: initializer is not a constant
src/libswscale/x86/ops.c(539): error C2099: initializer is not a constant
src/libswscale/x86/ops.c(540): error C2099: initializer is not a constant

Fixes: ec959e20c5
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 09:00:04 +01:00
Ramiro Polla
f436d885fc swscale/swscale: fix typos 2026-02-26 18:36:46 +00:00
Niklas Haas
ecb707f7e0 swscale/format: add assertion to guard UB
AVRational still can't handle 32-bit values...

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 18:08:49 +00:00
Niklas Haas
d4202809da swscale/format: check pixel type in ff_sws_encode/decode_colors()
This would otherwise generate illegal ops and undefined behavior, for
pixel formats without any supported corresponding pixel type.

This didn't cause any issues previously because the following
`ff_sws_encode_pixfmt` would normally fail for such formats, and the UB
was ignored in practice.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 18:08:49 +00:00