1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-24 13:56:33 +02:00

554 Commits

Author SHA1 Message Date
Michael Niedermayer
665b0cf3bf
swscale: 16bit planar float input support
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-01-21 21:06:14 +01:00
Andreas Rheinhardt
4973bb661e swscale/cms,graph,lut3d: Use ff_-prefix, don't export internal functions
Symbols with the sws_* prefix are exported.

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-01-12 15:41:39 +01:00
Niklas Haas
59258fb90e swscale/utils: lazily allocate XYZ tables on CONFIG_SMALL
This has the downside of requiring these tables to be recomputed on every
init, but saves ~270 kB of static data.

Signed-off-by: Niklas Haas <git@haasn.dev>
2024-12-26 20:31:36 +01:00
Niklas Haas
60bfafcd8a swscale/utils: add return code to fill_xyztables()
Needed for lazy allocation of XYZ tables.

Signed-off-by: Niklas Haas <git@haasn.dev>
2024-12-26 20:31:36 +01:00
Niklas Haas
af6d52eec6 swscale: use 16-bit intermediate precision for RGB/XYZ conversion
The current logic uses 12-bit linear light math, which is woefully insufficient
and leads to nasty postarization artifacts. This patch simply switches the
internal logic to 16-bit precision.

This raises the memory requirement of these tables from 32 kB to 272 kB.

All relevant FATE tests updated for improved accuracy.

Fixes: #4829
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-26 20:31:36 +01:00
Niklas Haas
7b7c32322d swscale/utils: fix XYZ primaries tagging
Swscale currently handles XYZ by embedding a forced conversion to
BT.709 RGB with a hardcoded matrix. This is not ideal, but to preserve the
status quo and avoid any unexpected changes in behavior, this patch merely
fixes the inferred primaries tag to match the reality.

In the future, I would like to handle XYZ properly, via direct conversion
to the target colorspace (or possibly simply by using a more fitting
RGB intermediate like SMPTE428), but for now just keep the status quo.
2024-12-23 12:33:43 +01:00
Niklas Haas
1f0c500784 swscale/utils: add helper function to infer colorspace metadata
Logic is loosely on equivalent decisions in libplacebo. The basic idea is to try
and be a bit conservative by treating AVCOL_*_UNSPECIFIED as a no-op, unless the
other primaries set are non-standard / wide-gamut or HDR. This helps avoid
unintended or unexpected colorspace conversions, while forcing it in cases where
we are almost certain it is needed. The major departure from libplacebo semantics
is that we no default to a 1000:1 contrast ration for SDR displays, instead modelling
them as idealized devices with an infinite contrast ratio.

In either case, setting SWS_STRICT overrides this behavior in favor of always
requiring explicit colorspace metadata.
2024-12-23 12:33:43 +01:00
Niklas Haas
9084d581e8 swscale/utils: read dynamic HDR10+ metadata from AVFrame
Logic ported from libplacebo's AVFrame helpers. The basic idea is to use the
provided MaxRGB/MaxSCL values to infer what the actual luminance would have
been, which HDR10+ metadata does not provide directly. It's worth pointing out
that this gives us an *upper* bound on the true maximum luminance, so any
error in the estimation cannot result in clipping.
2024-12-23 12:33:43 +01:00
Niklas Haas
7432fa19cd swscale/utils: read HDR mastering metadata from AVFrame 2024-12-23 12:33:43 +01:00
Niklas Haas
5b21b7f52c swscale/utils: set static/implied HDR metadata
Provide default values for the fields added in the previous commit.
2024-12-23 12:33:43 +01:00
Niklas Haas
a8d01dff9a swscale/utils: add HDR metadata to SwsFormat
Only add the condensed values that we actually care about. Group them into
a new struct to make it easier to discard or replace this metadata.

Define a special comparison function that does not choke on undefined/unknown
metadata.
2024-12-23 12:33:43 +01:00
Niklas Haas
b9dfe8138e swscale/utils: check for supported color transfers
We will use the av_csp_itu_eotf() functions to decode these internally, so
check this function to see if it succeeds.
2024-12-23 12:33:43 +01:00
Niklas Haas
2df655bc2c swscale/utils: fix sws_getCachedContext check
This logic was inverted, but || was not replaced by &&.

Fixes: ed5dd675624c83d9c69b406ce30e4e09f29970e3
Fixes: ticket #11353
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-18 17:30:26 +01:00
Niklas Haas
2f95bc3cb3 swscale/utils: disable full_chr_h_input optimization for odd width
The basic problem here is that the rgb*ToUV_half_* functions hard-code a
bilinear downsample from src[i] + src[i+1], with no bounds check on the i+1
access.

Due to the signature of the function, we cannot easily plumb the "true" width
into the function body to perform a bounds check. Similarly, we cannot easily
pre-pad the input because it is typically reading from the (const) input
frame, which would require a full memcpy to pad. Either of these solutions are
more trouble than the feature is worth, so just disable it on odd input sizes.

Fixes: use of uninitialized value
Fixes: ticket #11265
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-04 11:38:47 +01:00
Niklas Haas
2a091d4f2e swscale: introduce new, dynamic scaling API
As part of a larger, ongoing effort to modernize and partially rewrite
libswscale, it was decided and generally agreed upon to introduce a new
public API for libswscale. This API is designed to be less stateful, more
explicitly defined, and considerably easier to use than the existing one.

Most of the API work has been already accomplished in the previous commits,
this commit merely introduces the ability to use sws_scale_frame()
dynamically, without prior sws_init_context() calls. Instead, the new API
takes frame properties from the frames themselves, and the implementation is
based on the new SwsGraph API, which we simply reinitialize as needed.

This high-level wrapper also recreates the logic that used to live inside
vf_scale for scaling interlaced frames, enabling it to be reused more easily
by end users.

Finally, this function is designed to simply copy refs directly when nothing
needs to be done, substantially improving throughput of the noop fast path.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-25 11:03:50 +01:00
Niklas Haas
c461dcf291 swscale/internal: expose sws_init_single_context() internally
Used by the graph API swscale wrapper, for now.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-25 11:02:16 +01:00
Niklas Haas
6a91a165fd swscale: eliminate redundant SwsInternal accesses
This is a purely cosmetic commit aimed at replacing accesses to
SwsInternal.opts by direct access to SwsContext wherever convenient.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-25 10:59:52 +01:00
Niklas Haas
ed5dd67562 swscale: expose SwsContext publicly
Following in the footsteps of the work in the previous commit, it's now
relatively straightforward to expose the options struct publicly as
SwsContext. This is a step towards making this more user friendly, as
well as following API conventions established elsewhere.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-25 10:59:49 +01:00
Niklas Haas
2d077f9acd swscale/internal: group user-facing options together
This is a preliminary step to separating these into a new struct. This
commit contains no functional changes, it is a pure search-and-replace.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-21 12:49:56 +01:00
Niklas Haas
10d1be2621 swscale/internal: use static_assert for enforcing offsets
Instead of sprinkling av_assert0 into random init functions.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-21 12:47:43 +01:00
James Almer
271aea60a4 fate/pixfmts: extend the high bit depth test
Also test 8bit formats, and try bitdepth conversion paths.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-11-06 17:44:25 -03:00
James Almer
febc9e8162 swscale/output: add full chroma interpolation support for x2rgb10
Signed-off-by: James Almer <jamrial@gmail.com>
2024-11-02 15:01:31 -03:00
Ramiro Polla
7728b3357d swscale/range_convert: call arch-specific init functions from main init function
This commit also fixes the issue that the call to ff_sws_init_range_convert()
from sws_init_swscale() was not setting up the arch-specific optimizations.
2024-10-27 13:20:56 +01:00
James Almer
a67ba3c132 swscale/output: add XV48 output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-26 00:04:50 -03:00
James Almer
2f13f74791 swscale/input: add XV48 input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-26 00:04:29 -03:00
Niklas Haas
67adb30322 swscale: rename SwsContext to SwsInternal
And preserve the public SwsContext as separate name. The motivation here
is that I want to turn SwsContext into a public struct, while keeping the
internal implementation hidden. Additionally, I also want to be able to
use multiple internal implementations, e.g. for GPU devices.

This commit does not include any functional changes. For the most part, it is
a simple rename. The only complications arise from the public facing API
functions, which preserve their current type (and hence require an additional
unwrapping step internally), and the checkasm test framework, which directly
accesses SwsInternal.

For consistency, the affected functions that need to maintain a distionction
have generally been changed to refer to the SwsContext as *sws, and the
SwsInternal as *c.

In an upcoming commit, I will provide a backing definition for the public
SwsContext, and update `sws_internal()` to dereference the internal struct
instead of merely casting it.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-24 22:50:00 +02:00
Niklas Haas
b03c758600 swscale: add sws_is_noop()
Exactly what it says on the tin.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-23 23:06:55 +02:00
Niklas Haas
5e50a56b9c swscale: add new frame testing API
Replacing the old sws_isSupported* API with a more consistent family
of functions that follows the same signature and naming convention,
including a placeholder for testing the color space parameters that
we don't currently implement conversions for.

These functions also perform some extra basic sanity checking.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-23 23:06:16 +02:00
Niklas Haas
e2637a083a swscale/utils: add SwsFormat abstraction and helpers
Groups together all relevant color metadata from an AVFrame. While we could
use AVFrame directly, keeping it a separate struct has three advantages:

1. Functions accepting an SwsFormat will definitely not care about the
   data pointers.
2. It clearly separates sanitized and raw metadata, since the function to
   construct an SwsFormat from an AVFrame will also sanitize.
3. It's slightly more lightweight to pass around.

Move these into a new header file "utils.h" to avoid crowding
swscale_internal.h even more, and also to solve a circular dependency issue
down the line.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-23 23:04:06 +02:00
Niklas Haas
87baf9ab2c swscale: add sws_free_context()
Merely a convenience wrapper around sws_freeContext(). The name change is for
parity with the other sws_* functions.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-23 23:04:04 +02:00
Niklas Haas
fbfea1c644 swscale: publicly typedef struct SwsContext
Slightly more convenient, especially for the upcoming refactor which will
turn SwsContext into a public struct.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-23 23:00:54 +02:00
James Almer
b520d95467 swscale/output: add Y216LE output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-23 14:11:35 -03:00
James Almer
7756cd98ac swscale/input: add Y216LE input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-23 14:11:23 -03:00
James Almer
08c632ec0f swscale/output: add AYUV64BE output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-17 11:57:36 -03:00
James Almer
5a699c8db9 swscale/input: add AYUV64BE input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-17 11:57:36 -03:00
James Almer
42098f9266 swscale/output: add X36VBE output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-17 11:57:36 -03:00
James Almer
e012a7a24a swscale/input: add X36VBE input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-17 11:57:36 -03:00
Martin Schitter
d73b73af5e
swscale/input: add input support for RGBF16
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-10-14 20:46:24 +02:00
Martin Schitter
c72a5c486a
swscale/input: add input support for RGBF32
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-10-14 20:46:23 +02:00
James Almer
cd04ebe033 swscale/output: add V30X output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-12 10:08:29 -03:00
James Almer
57db8e0571 swscale/output: add VYU444 output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-12 10:08:29 -03:00
James Almer
eac9af382a swscale/output: add UYVA output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-12 10:08:29 -03:00
James Almer
6cd52c1080 swscale/output: add AYUV output support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-12 10:06:09 -03:00
James Almer
04612351ab swscale/input: add V30X input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-08 22:26:07 -03:00
James Almer
ea05edc9e0 swscale/input: add VYU444 input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-08 22:24:47 -03:00
James Almer
ec7f5e314d swscale/input: add UYVA input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-08 22:24:47 -03:00
James Almer
bb37d3c33e swscale/input: add AYUV input support
Signed-off-by: James Almer <jamrial@gmail.com>
2024-10-08 22:24:47 -03:00
Niklas Haas
286bdc9cdc swscale/internal: turn cascaded_tmp into an array
Slightly more convenient to access from the new wrapping code.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-10-07 19:51:34 +02:00
Niklas Haas
4ec45aca36 swscale/utils: fix leak on threaded ctx init failure
This count gets incremented after init succeeds, when it should be
incremented after *alloc* succeeds. Otherwise, we leak the context on
failure.

There are no negative consequences of incrementing for
allocated-but-not-initialized contexts, as the only functions that
reference it will, in the worst case, simply behave as if called on
allocated-but-not-initialized contexts, which is in line with expected
behavior when sws_init_context() fails.
2024-07-14 13:48:59 +02:00
Ramiro Polla
4f7f9b1026 swscale: remove unconditional #define DITHER1XBPP
This seems to have had an use in the past, but it is now defined
unconditionally.
2024-07-10 12:25:03 +02:00