PR #24971 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24971
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24971.patch


>From f94d9d5399d4ff9a8b0f3246431128765227991e Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 9 Oct 2026 18:07:44 +0200
Subject: [PATCH 1/4] swscale/tests/swscale: fix memleak on error

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/tests/swscale.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
index b5c51b9b04..e639571506 100644
--- a/libswscale/tests/swscale.c
+++ b/libswscale/tests/swscale.c
@@ -597,13 +597,17 @@ static int run_test(enum AVPixelFormat src_fmt, enum 
AVPixelFormat dst_fmt,
             goto error;
         if (opts->align_src) {
             ret = av_frame_get_buffer(src, opts->align_src);
-            if (ret < 0)
+            if (ret < 0) {
+                av_frame_free(&src);
                 goto error;
+            }
         }
 
         ret = checked_sws_scale_frame(sws_ref_src, src, ref);
-        if (ret < 0)
+        if (ret < 0) {
+            av_frame_free(&src);
             goto error;
+        }
         *psrc = src;
     }
 
-- 
2.52.0


>From ad9c7a20e0783841eea7f7ef6df328841d6e3c6c Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 9 Oct 2026 18:08:58 +0200
Subject: [PATCH 2/4] swscale/tests/swscale: don't bail on ENOTSUP in auxiliary
 conversions

Somebody thought it was a good idea to implement XYZ<->XYZ but not XYZ<->YUV,
so for an xyz -> xyz conversion, the main check succeeds while just the
auxiliary conversions fail.

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/tests/swscale.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
index e639571506..70ea5de2e1 100644
--- a/libswscale/tests/swscale.c
+++ b/libswscale/tests/swscale.c
@@ -618,11 +618,8 @@ static int run_test(enum AVPixelFormat src_fmt, enum 
AVPixelFormat dst_fmt,
     ret = (opts->api == IMPL_LEGACY) ? scale_legacy(dst, src, mode, opts, 
&r.time)
         : hw_device_ctx              ? scale_hw(dst, src, mode, opts, &r.time)
         :                              scale_new(dst, src, mode, opts, 
&r.time);
-    if (ret < 0) {
-        if (ret == AVERROR(ENOTSUP))
-            ret = 0;
+    if (ret < 0)
         goto error;
-    }
 
     ret = init_frame(&out, ref, ref->width, ref->height, ref->format);
     if (ret < 0)
@@ -670,6 +667,8 @@ bad_loss:
  error:
     av_frame_free(&dst);
     av_frame_free(&out);
+    if (ret == AVERROR(ENOTSUP))
+        ret = 0;
     return ret;
 }
 
-- 
2.52.0


>From 520a90e5fb7e48f6acf5c19d88f49f506710f65d Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 9 Oct 2026 17:52:19 +0200
Subject: [PATCH 3/4] swscale/format: reject XYZ<->RGB conversions

Fixes: 2ed5830108f92093cffb696e88706f970ce6bc6b
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/format.c         | 5 +++++
 tests/ref/fate/sws-ops-list | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libswscale/format.c b/libswscale/format.c
index 5484e8180c..a6530c2cd3 100644
--- a/libswscale/format.c
+++ b/libswscale/format.c
@@ -1837,6 +1837,11 @@ int ff_sws_op_list_generate(SwsContext *ctx, const 
SwsFormat *src,
         ctx->alpha_blend != SWS_ALPHA_BLEND_NONE)
         return AVERROR(ENOTSUP);
 
+    /* XYZ<->RGB conversion requires application of a gamma function which
+     * are not currently implemented */
+    if ((src->desc->flags ^ dst->desc->flags) & AV_PIX_FMT_FLAG_XYZ)
+        return AVERROR(ENOTSUP);
+
     SwsOpList *ops = ff_sws_op_list_alloc();
     if (!ops)
         return AVERROR(ENOMEM);
diff --git a/tests/ref/fate/sws-ops-list b/tests/ref/fate/sws-ops-list
index 59913a43f1..94a583b190 100644
--- a/tests/ref/fate/sws-ops-list
+++ b/tests/ref/fate/sws-ops-list
@@ -1 +1 @@
-1f03295f230be02367e812f3670230cc
+c49b616409175c41ccc5d786c5097f96
-- 
2.52.0


>From bb6c94512bc8fc9dcbedc2d5c8aefe18a8a7faa6 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 9 Oct 2026 17:53:49 +0200
Subject: [PATCH 4/4] swscale/format: remove switch/case hack (cosmetic)

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/format.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libswscale/format.c b/libswscale/format.c
index a6530c2cd3..f8c6462982 100644
--- a/libswscale/format.c
+++ b/libswscale/format.c
@@ -1522,10 +1522,11 @@ int ff_sws_decode_colors(SwsContext *ctx, SwsPixelType 
type,
         .lin  = fmt_decode_range(fmt, incomplete),
     }));
 
-    /* Final step, decode colorspace. XYZ formats carry no colorspace
-     * matrix; their transfer/primaries are handled by the color mapping
-     * layer, so treat them like RGB here. */
-    switch (fmt->desc->flags & AV_PIX_FMT_FLAG_XYZ ? AVCOL_SPC_RGB : fmt->csp) 
{
+    if (fmt->desc->flags & AV_PIX_FMT_FLAG_XYZ)
+        return 0; /* XYZ formats are treated as colorspaceless */
+
+    /* Final step, decode colorspace */
+    switch (fmt->csp) {
     case AVCOL_SPC_RGB:
         return 0;
     case AVCOL_SPC_UNSPECIFIED:
-- 
2.52.0

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

Reply via email to