This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 3503b19711cc6c0494ee5272a3fe28cc5bbb2889
Author:     Niklas Haas <[email protected]>
AuthorDate: Thu Mar 12 22:09:04 2026 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Thu Mar 12 22:09:04 2026 +0100

    swscale: add enum SwsScaler, SwsContext.scaler to replace legacy flags
    
    Another step towards a cleaner API, with a cleaner separation of purposes.
    Also avoids wasting a whopping one third of the flag space on what really
    shouldn't have been a flag to begin with.
    
    I pre-emptively decided to separate the scaler selection between "scaler"
    and "scaler_sub", the latter defining what's used for things like 4:2:0
    subsampling.
    
    This allows us to get rid of the awkwardly defined SWS_BICUBLIN flag, in 
favor
    of that just being the natural consequence of using a different scaler_sub.
    
    Lastly, I also decided to pre-emptively axe the poorly defined and
    questionable SWS_X scaler, which I doubt ever saw much use. The old flag
    is still available as a deprecated flag, anyhow.
    
    Sponsored-by: Sovereign Tech Fund
    Signed-off-by: Niklas Haas <[email protected]>
---
 doc/APIchanges       |  3 +++
 libswscale/graph.c   |  4 ++++
 libswscale/options.c | 13 +++++++++++++
 libswscale/swscale.h | 30 ++++++++++++++++++++++++++++++
 libswscale/utils.c   | 21 +++++++++++++++++++--
 libswscale/version.h |  2 +-
 6 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index d4b573b0d6..f540a99831 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
 
 API changes, most recent first:
 
+2026-03-12 - xxxxxxxxxx - lsws 9.7.100 - swscale.h
+  Add enum SwsScaler, and SwsContext.scaler/scaler_sub.
+
 2026-03-11 - 910000fe59d - lavu 60.28.100 - hwcontext_amf.h
   Add av_amf_display_mastering_meta_to_hdrmeta(), 
av_amf_light_metadata_to_hdrmeta().
   Add av_amf_extract_hdr_metadata(), av_amf_attach_hdr_metadata().
diff --git a/libswscale/graph.c b/libswscale/graph.c
index 145dfe2277..db11591862 100644
--- a/libswscale/graph.c
+++ b/libswscale/graph.c
@@ -502,6 +502,8 @@ static int add_legacy_sws_pass(SwsGraph *graph, const 
SwsFormat *src,
     sws->dither      = ctx->dither;
     sws->alpha_blend = ctx->alpha_blend;
     sws->gamma_flag  = ctx->gamma_flag;
+    sws->scaler      = ctx->scaler;
+    sws->scaler_sub  = ctx->scaler_sub;
 
     sws->src_w       = src->width;
     sws->src_h       = src->height;
@@ -830,6 +832,8 @@ static int opts_equal(const SwsContext *c1, const 
SwsContext *c2)
            c1->dst_h_chr_pos == c2->dst_h_chr_pos &&
            c1->dst_v_chr_pos == c2->dst_v_chr_pos &&
            c1->intent        == c2->intent        &&
+           c1->scaler        == c2->scaler        &&
+           c1->scaler_sub    == c2->scaler_sub    &&
            !memcmp(c1->scaler_params, c2->scaler_params, 
sizeof(c1->scaler_params));
 
 }
diff --git a/libswscale/options.c b/libswscale/options.c
index 06e51dcfe9..004988488c 100644
--- a/libswscale/options.c
+++ b/libswscale/options.c
@@ -52,6 +52,19 @@ static const AVOption swscale_options[] = {
         { "error_diffusion", "error diffusion dither",        0,  
AV_OPT_TYPE_CONST, { .i64 = SWS_ERROR_DIFFUSION}, .flags = VE, .unit = 
"sws_flags" },
         { "unstable",        "allow experimental new code",   0,  
AV_OPT_TYPE_CONST, { .i64 = SWS_UNSTABLE       }, .flags = VE, .unit = 
"sws_flags" },
 
+    { "scaler",          "set scaling algorithm",         OFFSET(scaler),      
 AV_OPT_TYPE_INT,    { .i64 = SWS_SCALE_AUTO     }, .flags = VE, .unit = 
"sws_scaler", .max = SWS_SCALE_NB - 1 },
+    { "scaler_sub",      "set subsampling algorithm",     OFFSET(scaler_sub),  
 AV_OPT_TYPE_INT,    { .i64 = SWS_SCALE_AUTO     }, .flags = VE, .unit = 
"sws_scaler", .max = SWS_SCALE_NB - 1 },
+        { "auto",        "automatic selection",           0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_AUTO     }, .flags = VE, .unit = 
"sws_scaler" },
+        { "bilinear",    "bilinear filtering",            0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_BILINEAR }, .flags = VE, .unit = 
"sws_scaler" },
+        { "bicubic",     "2-tap cubic B-spline",          0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_BICUBIC  }, .flags = VE, .unit = 
"sws_scaler" },
+        { "point",       "point sampling",                0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_POINT    }, .flags = VE, .unit = 
"sws_scaler" },
+        { "neighbor",    "nearest neighbor",              0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_POINT    }, .flags = VE, .unit = 
"sws_scaler" },
+        { "area",        "area averaging",                0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_AREA     }, .flags = VE, .unit = 
"sws_scaler" },
+        { "gaussian",    "2-tap gaussian approximation",  0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_GAUSSIAN }, .flags = VE, .unit = 
"sws_scaler" },
+        { "sinc",        "unwindowed sinc",               0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_SINC     }, .flags = VE, .unit = 
"sws_scaler" },
+        { "lanczos",     "3-tap sinc/sinc",               0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_LANCZOS  }, .flags = VE, .unit = 
"sws_scaler" },
+        { "spline",      "2-tap cubic BC spline",         0,                   
 AV_OPT_TYPE_CONST,  { .i64 = SWS_SCALE_SPLINE   }, .flags = VE, .unit = 
"sws_scaler" },
+
     { "param0",          "scaler param 0", OFFSET(scaler_params[0]), 
AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX, VE },
     { "param1",          "scaler param 1", OFFSET(scaler_params[1]), 
AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT  }, INT_MIN, INT_MAX, VE },
 
diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index 043b4c15ef..14c7d4cc57 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -93,6 +93,20 @@ typedef enum SwsAlphaBlend {
     SWS_ALPHA_BLEND_MAX_ENUM = 0x7FFFFFFF, /* force size to 32 bits, not a 
valid blend mode */
 } SwsAlphaBlend;
 
+typedef enum SwsScaler {
+    SWS_SCALE_AUTO = 0,
+    SWS_SCALE_BILINEAR, ///< bilinear filtering
+    SWS_SCALE_BICUBIC,  ///< 2-tap cubic BC-spline
+    SWS_SCALE_POINT,    ///< nearest neighbor (point sampling)
+    SWS_SCALE_AREA,     ///< area averaging
+    SWS_SCALE_GAUSSIAN, ///< 2-tap gaussian approximation
+    SWS_SCALE_SINC,     ///< unwindowed sinc
+    SWS_SCALE_LANCZOS,  ///< 3-tap sinc/sinc
+    SWS_SCALE_SPLINE,   ///< unwindowned natural cubic spline
+    SWS_SCALE_NB,       ///< not part of the ABI
+    SWS_SCALE_MAX_ENUM = 0x7FFFFFFF, ///< force size to 32 bits, not a valid 
filter type
+} SwsScaler;
+
 typedef enum SwsFlags {
     /**
      * Scaler selection options. Only one may be active at a time.
@@ -249,6 +263,22 @@ typedef struct SwsContext {
      */
     int intent;
 
+    /**
+     * Scaling filter. If set to something other than SWS_SCALE_AUTO, this will
+     * override the filter implied by `SwsContext.flags`.
+     *
+     * Note: Does not affect the legacy (stateful) API.
+     */
+    SwsScaler scaler;
+
+    /**
+     * Scaler used specifically for up/downsampling subsampled (chroma) planes.
+     * If set to something other than SWS_SCALE_AUTO, this will override the
+     * filter implied by `SwsContext.scaler`. Otherwise, the same filter
+     * will be used for both main scaling and chroma subsampling.
+     */
+    SwsScaler scaler_sub;
+
     /* Remember to add new fields to graph.c:opts_equal() */
 } SwsContext;
 
diff --git a/libswscale/utils.c b/libswscale/utils.c
index a0da6bc5b6..84d4834903 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1117,6 +1117,22 @@ static enum AVPixelFormat alphaless_fmt(enum 
AVPixelFormat fmt)
     }
 }
 
+static int scaler_flag(SwsScaler scaler, int fallback)
+{
+    switch (scaler) {
+    case SWS_SCALE_BILINEAR: return SWS_BILINEAR; break;
+    case SWS_SCALE_BICUBIC:  return SWS_BICUBIC;  break;
+    case SWS_SCALE_POINT:    return SWS_POINT;    break;
+    case SWS_SCALE_AREA:     return SWS_AREA;     break;
+    case SWS_SCALE_GAUSSIAN: return SWS_GAUSS;    break;
+    case SWS_SCALE_SINC:     return SWS_SINC;     break;
+    case SWS_SCALE_LANCZOS:  return SWS_LANCZOS;  break;
+    case SWS_SCALE_SPLINE:   return SWS_SPLINE;   break;
+    default:
+        return fallback;
+    }
+}
+
 av_cold int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter,
                                        SwsFilter *dstFilter)
 {
@@ -1212,8 +1228,9 @@ av_cold int ff_sws_init_single_context(SwsContext *sws, 
SwsFilter *srcFilter,
         }
     }
 
-    int lum_scaler = i == SWS_BICUBLIN ? SWS_BICUBIC  : i;
-    int chr_scaler = i == SWS_BICUBLIN ? SWS_BILINEAR : i;
+    SwsScaler scaler_sub = sws->scaler_sub ? sws->scaler_sub : sws->scaler;
+    int lum_scaler = scaler_flag(sws->scaler, i == SWS_BICUBLIN ? SWS_BICUBIC  
: i);
+    int chr_scaler = scaler_flag(scaler_sub,  i == SWS_BICUBLIN ? SWS_BILINEAR 
: i);
 
     /* sanity check */
     if (srcW < 1 || srcH < 1 || dstW < 1 || dstH < 1) {
diff --git a/libswscale/version.h b/libswscale/version.h
index f573bef6fc..4c6af261e6 100644
--- a/libswscale/version.h
+++ b/libswscale/version.h
@@ -28,7 +28,7 @@
 
 #include "version_major.h"
 
-#define LIBSWSCALE_VERSION_MINOR   6
+#define LIBSWSCALE_VERSION_MINOR   7
 #define LIBSWSCALE_VERSION_MICRO 100
 
 #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to