[FFmpeg-cvslog] swscale: Take the destination range into account for yuv->rgb->yuv conversions

Martin Storsjö git at videolan.org
Fri Feb 25 11:13:11 EET 2022


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Feb 18 14:35:31 2022 +0200| [c523724c693ee031d8b5351aff6232a1f7d86876] | committer: Martin Storsjö

swscale: Take the destination range into account for yuv->rgb->yuv conversions

The range parameters need to be set up before calling
sws_init_context (which selects which fastpaths can be used;
this gets called by sws_getContext); solely passing them via
sws_setColorspaceDetails isn't enough.

This fixes producing full range YUV range output when doing
YUV->YUV conversions between different YUV color spaces.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c523724c693ee031d8b5351aff6232a1f7d86876
---

 libswscale/utils.c                | 11 ++++++++---
 tests/fate/libswscale.mak         | 16 ++++++++++++++++
 tests/ref/fate/sws-yuv-colorspace |  6 ++++++
 tests/ref/fate/sws-yuv-range      |  6 ++++++
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 7c8e1bbdde..34f7f0b869 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1037,11 +1037,16 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
                                      srcRange, table, dstRange,
                                      brightness, contrast, saturation);
 
-            c->cascaded_context[1] = sws_getContext(tmp_width, tmp_height, tmp_format,
-                                                    dstW, dstH, c->dstFormat,
-                                                    c->flags, NULL, NULL, c->param);
+            c->cascaded_context[1] = sws_alloc_set_opts(tmp_width, tmp_height, tmp_format,
+                                                        dstW, dstH, c->dstFormat,
+                                                        c->flags, c->param);
             if (!c->cascaded_context[1])
                 return -1;
+            c->cascaded_context[1]->srcRange = srcRange;
+            c->cascaded_context[1]->dstRange = dstRange;
+            ret = sws_init_context(c->cascaded_context[1], NULL , NULL);
+            if (ret < 0)
+                return ret;
             sws_setColorspaceDetails(c->cascaded_context[1], inv_table,
                                      srcRange, table, dstRange,
                                      0, 1 << 16, 1 << 16);
diff --git a/tests/fate/libswscale.mak b/tests/fate/libswscale.mak
index cf9319ec44..f8572f9c37 100644
--- a/tests/fate/libswscale.mak
+++ b/tests/fate/libswscale.mak
@@ -17,6 +17,22 @@ $(SWS_SLICE_TEST-yes): tools/scale_slice_test$(EXESUF)
 $(SWS_SLICE_TEST-yes): REF = /dev/null
 FATE_LIBSWSCALE_SAMPLES += $(SWS_SLICE_TEST-yes)
 
+FATE_LIBSWSCALE-$(CONFIG_RAWVIDEO_DEMUXER) += fate-sws-yuv-colorspace
+fate-sws-yuv-colorspace: tests/data/vsynth1.yuv
+fate-sws-yuv-colorspace: ffmpeg$(PROGSSUF)$(EXESUF)
+fate-sws-yuv-colorspace: CMD = framecrc \
+  -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv \
+  -frames 1 \
+  -vf scale=in_color_matrix=bt709:in_range=limited:out_color_matrix=bt601:out_range=full:flags=+accurate_rnd+bitexact
+
+FATE_LIBSWSCALE-$(CONFIG_RAWVIDEO_DEMUXER) += fate-sws-yuv-range
+fate-sws-yuv-range: tests/data/vsynth1.yuv
+fate-sws-yuv-range: ffmpeg$(PROGSSUF)$(EXESUF)
+fate-sws-yuv-range: CMD = framecrc \
+  -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv \
+  -frames 1 \
+  -vf scale=in_color_matrix=bt601:in_range=limited:out_color_matrix=bt601:out_range=full:flags=+accurate_rnd+bitexact
+
 FATE_LIBSWSCALE += $(FATE_LIBSWSCALE-yes)
 FATE_LIBSWSCALE_SAMPLES += $(FATE_LIBSWSCALE_SAMPLES-yes)
 FATE-$(CONFIG_SWSCALE) += $(FATE_LIBSWSCALE)
diff --git a/tests/ref/fate/sws-yuv-colorspace b/tests/ref/fate/sws-yuv-colorspace
new file mode 100644
index 0000000000..bcf3c4b89c
--- /dev/null
+++ b/tests/ref/fate/sws-yuv-colorspace
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0xcbcb97b9
diff --git a/tests/ref/fate/sws-yuv-range b/tests/ref/fate/sws-yuv-range
new file mode 100644
index 0000000000..5b6f93b225
--- /dev/null
+++ b/tests/ref/fate/sws-yuv-range
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0xe75c71a9



More information about the ffmpeg-cvslog mailing list