This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 0611abc1bb5f31f52506f735f8a3a760fb309586 Author: Niklas Haas <[email protected]> AuthorDate: Wed Apr 22 15:04:16 2026 +0200 Commit: Niklas Haas <[email protected]> CommitDate: Fri May 15 18:53:05 2026 +0200 swscale/graph: move code for adding filters to format.h Mirroring the precedent established by the other SwsOp-generating functions. This allows us to re-use it for the uops macro generator. Signed-off-by: Niklas Haas <[email protected]> --- libswscale/format.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libswscale/format.h | 8 ++++++ libswscale/graph.c | 76 +-------------------------------------------------- 3 files changed, 88 insertions(+), 75 deletions(-) diff --git a/libswscale/format.c b/libswscale/format.c index c62cff1e53..365f3a7297 100644 --- a/libswscale/format.c +++ b/libswscale/format.c @@ -1551,4 +1551,83 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, }); } +static SwsScaler get_scaler_fallback(SwsContext *ctx) +{ + if (ctx->scaler != SWS_SCALE_AUTO) + return ctx->scaler; + + /* Backwards compatibility with legacy flags API */ + if (ctx->flags & SWS_BILINEAR) { + return SWS_SCALE_BILINEAR; + } else if (ctx->flags & (SWS_BICUBIC | SWS_BICUBLIN)) { + return SWS_SCALE_BICUBIC; + } else if (ctx->flags & SWS_POINT) { + return SWS_SCALE_POINT; + } else if (ctx->flags & SWS_AREA) { + return SWS_SCALE_AREA; + } else if (ctx->flags & SWS_GAUSS) { + return SWS_SCALE_GAUSSIAN; + } else if (ctx->flags & SWS_SINC) { + return SWS_SCALE_SINC; + } else if (ctx->flags & SWS_LANCZOS) { + return SWS_SCALE_LANCZOS; + } else if (ctx->flags & SWS_SPLINE) { + return SWS_SCALE_SPLINE; + } else { + return SWS_SCALE_AUTO; + } +} + +static int add_filter(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, + SwsOpType filter, int src_size, int dst_size) +{ + if (src_size == dst_size) + return 0; /* no-op */ + + SwsFilterParams params = { + .scaler = get_scaler_fallback(ctx), + .src_size = src_size, + .dst_size = dst_size, + }; + + for (int i = 0; i < SWS_NUM_SCALER_PARAMS; i++) + params.scaler_params[i] = ctx->scaler_params[i]; + + SwsFilterWeights *kernel; + int ret = ff_sws_filter_generate(ctx, ¶ms, &kernel); + if (ret == AVERROR(ENOTSUP)) { + /* Filter size exceeds limit; cascade with geometric mean size */ + int mean = sqrt((int64_t) src_size * dst_size); + if (mean == src_size || mean == dst_size) + return AVERROR_BUG; /* sanity, prevent infinite loop */ + ret = add_filter(ctx, type, ops, filter, src_size, mean); + if (ret < 0) + return ret; + return add_filter(ctx, type, ops, filter, mean, dst_size); + } else if (ret < 0) { + return ret; + } + + return ff_sws_op_list_append(ops, &(SwsOp) { + .type = type, + .op = filter, + .filter.kernel = kernel, + }); +} + +int ff_sws_add_filters(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, + const SwsFormat *src, const SwsFormat *dst) +{ + /** + * Always perform horizontal scaling first, since it's much more likely to + * benefit from small integer optimizations; we should maybe flip the order + * here if we're downscaling the vertical resolution by a lot, though. + */ + int ret = add_filter(ctx, type, ops, SWS_OP_FILTER_H, src->width, dst->width); + if (ret < 0) + return ret; + + return add_filter(ctx, type, ops, SWS_OP_FILTER_V, src->height, dst->height); +} + #endif /* CONFIG_UNSTABLE */ diff --git a/libswscale/format.h b/libswscale/format.h index 61a8039f56..4f2d1427cb 100644 --- a/libswscale/format.h +++ b/libswscale/format.h @@ -178,6 +178,14 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, const SwsFormat *src, const SwsFormat *dst, bool *incomplete); +/** + * Append a set of operations for scaling pixels to a different resolution. + * + * Returns 0 on success, or a negative error code on failure. + */ +int ff_sws_add_filters(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, + const SwsFormat *src, const SwsFormat *dst); + /** * Represents a view into a single field of frame data. * diff --git a/libswscale/graph.c b/libswscale/graph.c index 403b66399e..543ac5973c 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -570,70 +570,6 @@ static int add_legacy_sws_pass(SwsGraph *graph, const SwsFormat *src, *********************************/ #if CONFIG_UNSTABLE -static SwsScaler get_scaler_fallback(SwsContext *ctx) -{ - if (ctx->scaler != SWS_SCALE_AUTO) - return ctx->scaler; - - /* Backwards compatibility with legacy flags API */ - if (ctx->flags & SWS_BILINEAR) { - return SWS_SCALE_BILINEAR; - } else if (ctx->flags & (SWS_BICUBIC | SWS_BICUBLIN)) { - return SWS_SCALE_BICUBIC; - } else if (ctx->flags & SWS_POINT) { - return SWS_SCALE_POINT; - } else if (ctx->flags & SWS_AREA) { - return SWS_SCALE_AREA; - } else if (ctx->flags & SWS_GAUSS) { - return SWS_SCALE_GAUSSIAN; - } else if (ctx->flags & SWS_SINC) { - return SWS_SCALE_SINC; - } else if (ctx->flags & SWS_LANCZOS) { - return SWS_SCALE_LANCZOS; - } else if (ctx->flags & SWS_SPLINE) { - return SWS_SCALE_SPLINE; - } else { - return SWS_SCALE_AUTO; - } -} - -static int add_filter(SwsContext *ctx, SwsPixelType type, SwsOpList *ops, - SwsOpType filter, int src_size, int dst_size) -{ - if (src_size == dst_size) - return 0; /* no-op */ - - SwsFilterParams params = { - .scaler = get_scaler_fallback(ctx), - .src_size = src_size, - .dst_size = dst_size, - }; - - for (int i = 0; i < SWS_NUM_SCALER_PARAMS; i++) - params.scaler_params[i] = ctx->scaler_params[i]; - - SwsFilterWeights *kernel; - int ret = ff_sws_filter_generate(ctx, ¶ms, &kernel); - if (ret == AVERROR(ENOTSUP)) { - /* Filter size exceeds limit; cascade with geometric mean size */ - int mean = sqrt((int64_t) src_size * dst_size); - if (mean == src_size || mean == dst_size) - return AVERROR_BUG; /* sanity, prevent infinite loop */ - ret = add_filter(ctx, type, ops, filter, src_size, mean); - if (ret < 0) - return ret; - return add_filter(ctx, type, ops, filter, mean, dst_size); - } else if (ret < 0) { - return ret; - } - - return ff_sws_op_list_append(ops, &(SwsOp) { - .type = type, - .op = filter, - .filter.kernel = kernel, - }); -} - static int add_convert_pass(SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, SwsPass *input, SwsPass **output) @@ -665,19 +601,9 @@ static int add_convert_pass(SwsGraph *graph, const SwsFormat *src, ret = ff_sws_decode_colors(ctx, type, ops, src, &graph->incomplete); if (ret < 0) goto fail; - - /** - * Always perform horizontal scaling first, since it's much more likely to - * benefit from small integer optimizations; we should maybe flip the order - * here if we're downscaling the vertical resolution by a lot, though. - */ - ret = add_filter(ctx, type, ops, SWS_OP_FILTER_H, src->width, dst->width); + ret = ff_sws_add_filters(ctx, type, ops, src, dst); if (ret < 0) goto fail; - ret = add_filter(ctx, type, ops, SWS_OP_FILTER_V, src->height, dst->height); - if (ret < 0) - goto fail; - ret = ff_sws_encode_colors(ctx, type, ops, src, dst, &graph->incomplete); if (ret < 0) goto fail; _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
