This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 6df223ce02e94b3e0d546a64796b2101b6db133f Author: Niklas Haas <[email protected]> AuthorDate: Mon Jun 1 18:04:29 2026 +0200 Commit: Niklas Haas <[email protected]> CommitDate: Wed Jun 3 21:39:55 2026 +0000 swscale/format: generalize ff_test_fmt() to take SwsBackend This allows us to test support in either the legacy code, or the ops-based code, or both. Signed-off-by: Niklas Haas <[email protected]> --- libswscale/format.c | 45 ++++++++++++++++++++++++++++++++++++++++----- libswscale/format.h | 13 ++++++++++++- libswscale/swscale.c | 5 +++-- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/libswscale/format.c b/libswscale/format.c index 7782a0233d..b9a25ed5a1 100644 --- a/libswscale/format.c +++ b/libswscale/format.c @@ -554,11 +554,27 @@ bool ff_infer_colors(SwsColor *src, SwsColor *dst) return incomplete; } -int sws_test_format(enum AVPixelFormat format, int output) +/* Variant of sws_test_format() for the ops-based code */ +static int test_format_ops(enum AVPixelFormat format, int output); +static int test_format_legacy(enum AVPixelFormat format, int output) { return output ? sws_isSupportedOutput(format) : sws_isSupportedInput(format); } +int ff_sws_test_pixfmt_backend(const SwsBackend backends, + enum AVPixelFormat format, int output) +{ + /* The only non-ops backend is the legacy backend */ + const SwsBackend backends_ops = SWS_BACKEND_ALL ^ SWS_BACKEND_LEGACY; + return ((backends & SWS_BACKEND_LEGACY) && test_format_legacy(format, output)) || + ((backends & backends_ops) && test_format_ops(format, output)); +} + +int sws_test_format(enum AVPixelFormat format, int output) +{ + return ff_sws_test_pixfmt_backend(SWS_BACKEND_STABLE, format, output); +} + int sws_test_hw_format(enum AVPixelFormat format) { switch (format) { @@ -611,10 +627,10 @@ static int test_loc(enum AVChromaLocation loc) return (unsigned)loc < AVCHROMA_LOC_NB; } -int ff_test_fmt(const SwsFormat *fmt, int output) +int ff_test_fmt(const SwsBackend backends, const SwsFormat *fmt, int output) { return fmt->width > 0 && fmt->height > 0 && - sws_test_format (fmt->format, output) && + ff_sws_test_pixfmt_backend(backends, fmt->format, output) && sws_test_colorspace(fmt->csp, output) && sws_test_primaries (fmt->color.prim, output) && sws_test_transfer (fmt->color.trc, output) && @@ -627,7 +643,7 @@ int sws_test_frame(const AVFrame *frame, int output) { for (int field = 0; field < 2; field++) { const SwsFormat fmt = ff_fmt_from_frame(frame, field); - if (!ff_test_fmt(&fmt, output)) + if (!ff_test_fmt(SWS_BACKEND_STABLE, &fmt, output)) return 0; if (!fmt.interlaced) break; @@ -907,6 +923,18 @@ static int fmt_analyze(enum AVPixelFormat fmt, SwsReadWriteOp *rw_op, return 0; } +static int test_format_ops(enum AVPixelFormat format, int output) +{ + SwsReadWriteOp rw; + SwsSwizzleOp swizzle; + SwsPackOp pack; + SwsShiftOp shift; + SwsPixelType pixel_type, raw_type; + int ret = fmt_analyze(format, &rw, &pack, &swizzle, &shift, + &pixel_type, &raw_type); + return ret == 0; +} + static SwsSwizzleOp swizzle_inv(SwsSwizzleOp swiz) { /* Input[x] =: Output[swizzle.x] */ unsigned out[4]; @@ -1670,4 +1698,11 @@ fail: return ret; } -#endif /* CONFIG_UNSTABLE */ +#else /* !CONFIG_UNSTABLE */ + +static int test_format_ops(enum AVPixelFormat format, int output) +{ + return 0; +} + +#endif diff --git a/libswscale/format.h b/libswscale/format.h index 844ea353b3..67f25d7006 100644 --- a/libswscale/format.h +++ b/libswscale/format.h @@ -149,7 +149,18 @@ static inline int ff_fmt_align(enum AVPixelFormat fmt) } } -int ff_test_fmt(const SwsFormat *fmt, int output); +/* Internal helper to test a format for either the legacy backend or the + * ops-based backends, depending on `backends` (must be nonzero). */ +int ff_sws_test_pixfmt_backend(const SwsBackend backends, + enum AVPixelFormat format, int output); + +/** + * Statically test if a given format is supported by the given set of + * backends. This is a heuristic, which may have false positives if a + * specific backend does not actually implement all operations that would be + * required to support the format. + */ +int ff_test_fmt(SwsBackend backends, const SwsFormat *fmt, int output); /* Returns true if the formats are incomplete, false otherwise */ bool ff_infer_colors(SwsColor *src, SwsColor *dst); diff --git a/libswscale/swscale.c b/libswscale/swscale.c index ca7eddbdef..558e332eb2 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1488,6 +1488,7 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) } int dst_width = dst->width; + const SwsBackend backends = ff_sws_enabled_backends(ctx); for (int field = 0; field < 2; field++) { SwsFormat src_fmt = ff_fmt_from_frame(src, field); SwsFormat dst_fmt = ff_fmt_from_frame(dst, field); @@ -1499,8 +1500,8 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src) goto fail; } - src_ok = ff_test_fmt(&src_fmt, 0); - dst_ok = ff_test_fmt(&dst_fmt, 1); + src_ok = ff_test_fmt(backends, &src_fmt, 0); + dst_ok = ff_test_fmt(backends, &dst_fmt, 1); if ((!src_ok || !dst_ok) && !ff_props_equal(&src_fmt, &dst_fmt)) { err_msg = src_ok ? "Unsupported output" : "Unsupported input"; ret = AVERROR(ENOTSUP); _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
