PR #26223 opened by Pu Cheng (GeekQAQ)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26223
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26223.patch

sws_init_context() sets src_range / dst_range to 1 for YUVJ and gray
formats (handle_jpeg()), so these public options no longer hold what the
caller set. When sws_getCachedContext() creates a new context for
different parameters, it copies the options of the old one with
av_opt_copy(), including the ranges rewritten for the old formats.
Scaling to gray first and then, through sws_getCachedContext(), from
yuv420p to yuv420p thus keeps dst_range at 1 and converts to full range,
while a newly created context for the same parameters keeps the range.

Reset both ranges after copying the options, as sws_getCachedContext()
takes no range arguments.

Signed-off-by: Pu Cheng <[email protected]>



>From 3bea79d719721689b14da5623864b571317ebc1e Mon Sep 17 00:00:00 2001
From: Pu Cheng <[email protected]>
Date: Fri, 20 Nov 2026 14:34:00 +0800
Subject: [PATCH] swscale/utils: do not inherit modified ranges in
 sws_getCachedContext()

sws_init_context() sets src_range / dst_range to 1 for YUVJ and gray
formats (handle_jpeg()), so these public options no longer hold what the
caller set. When sws_getCachedContext() creates a new context for
different parameters, it copies the options of the old one with
av_opt_copy(), including the ranges rewritten for the old formats.
Scaling to gray first and then, through sws_getCachedContext(), from
yuv420p to yuv420p thus keeps dst_range at 1 and converts to full range,
while a newly created context for the same parameters keeps the range.

Reset both ranges after copying the options, as sws_getCachedContext()
takes no range arguments.

Signed-off-by: Pu Cheng <[email protected]>
---
 libswscale/utils.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 0cd80ede650..be7324a9499 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2450,6 +2450,9 @@ SwsContext *sws_getCachedContext(SwsContext *prev, int 
srcW,
 
     if (prev) {
         av_opt_copy(sws, prev);
+        /* src_range/dst_range may have been rewritten by sws_init_context()
+         * for the previous formats; start from the defaults for the new ones 
*/
+        sws->src_range = sws->dst_range = 0;
         sws_free_context(&prev);
     }
 
-- 
2.54.1

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

Reply via email to