From: "Martin Storsjö" <martin@martin.st> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2] swscale: Take the destination range into account for yuv->rgb->yuv conversions Date: Wed, 23 Feb 2022 21:45:53 +0200 Message-ID: <20220223194553.59514-1-martin@martin.st> (raw) In-Reply-To: <20220219154831.GW2829255@pb2> 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@martin.st> --- 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(-) create mode 100644 tests/ref/fate/sws-yuv-colorspace create mode 100644 tests/ref/fate/sws-yuv-range 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 -- 2.32.0 (Apple Git-132) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-23 19:46 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-18 14:45 [FFmpeg-devel] [PATCH] " Martin Storsjö 2022-02-19 15:48 ` Michael Niedermayer 2022-02-19 21:43 ` Martin Storsjö 2022-02-23 19:45 ` Martin Storsjö [this message] 2022-02-24 22:50 ` [FFmpeg-devel] [PATCH v2] " Michael Niedermayer 2022-02-25 9:13 ` Martin Storsjö
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220223194553.59514-1-martin@martin.st \ --to=martin@martin.st \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git