* [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions @ 2022-02-18 14:45 Martin Storsjö 2022-02-19 15:48 ` Michael Niedermayer 0 siblings, 1 reply; 6+ messages in thread From: Martin Storsjö @ 2022-02-18 14:45 UTC (permalink / raw) To: ffmpeg-devel 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 ++++++++--- 1 file changed, 8 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); -- 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions 2022-02-18 14:45 [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions Martin Storsjö @ 2022-02-19 15:48 ` Michael Niedermayer 2022-02-19 21:43 ` Martin Storsjö 2022-02-23 19:45 ` [FFmpeg-devel] [PATCH v2] " Martin Storsjö 0 siblings, 2 replies; 6+ messages in thread From: Michael Niedermayer @ 2022-02-19 15:48 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 1085 bytes --] On Fri, Feb 18, 2022 at 04:45:46PM +0200, Martin Storsjö wrote: > 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 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) Probably ok please add a fate test for this thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Modern terrorism, a quick summary: Need oil, start war with country that has oil, kill hundread thousand in war. Let country fall into chaos, be surprised about raise of fundamantalists. Drop more bombs, kill more people, be surprised about them taking revenge and drop even more bombs and strip your own citizens of their rights and freedoms. to be continued [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions 2022-02-19 15:48 ` Michael Niedermayer @ 2022-02-19 21:43 ` Martin Storsjö 2022-02-23 19:45 ` [FFmpeg-devel] [PATCH v2] " Martin Storsjö 1 sibling, 0 replies; 6+ messages in thread From: Martin Storsjö @ 2022-02-19 21:43 UTC (permalink / raw) To: FFmpeg development discussions and patches On Sat, 19 Feb 2022, Michael Niedermayer wrote: > On Fri, Feb 18, 2022 at 04:45:46PM +0200, Martin Storsjö wrote: >> 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 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) > > Probably ok > > please add a fate test for this Sure. I'm not offhand familiar with what kinds of tests we have for swscale right now, and where a test for this would fit in best. (It's reproducible by converting from e.g. BT601 to BT709 or vice versa, when the output is supposed to be full range.) // Martin _______________________________________________ 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH v2] swscale: Take the destination range into account for yuv->rgb->yuv conversions 2022-02-19 15:48 ` Michael Niedermayer 2022-02-19 21:43 ` Martin Storsjö @ 2022-02-23 19:45 ` Martin Storsjö 2022-02-24 22:50 ` Michael Niedermayer 1 sibling, 1 reply; 6+ messages in thread From: Martin Storsjö @ 2022-02-23 19:45 UTC (permalink / raw) To: ffmpeg-devel 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] swscale: Take the destination range into account for yuv->rgb->yuv conversions 2022-02-23 19:45 ` [FFmpeg-devel] [PATCH v2] " Martin Storsjö @ 2022-02-24 22:50 ` Michael Niedermayer 2022-02-25 9:13 ` Martin Storsjö 0 siblings, 1 reply; 6+ messages in thread From: Michael Niedermayer @ 2022-02-24 22:50 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 1307 bytes --] On Wed, Feb 23, 2022 at 09:45:53PM +0200, Martin Storsjö wrote: > 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 LGTM tested on mingw32/64 + wine / linux x86 32/64bit, arm/mips qemu thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt. [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] swscale: Take the destination range into account for yuv->rgb->yuv conversions 2022-02-24 22:50 ` Michael Niedermayer @ 2022-02-25 9:13 ` Martin Storsjö 0 siblings, 0 replies; 6+ messages in thread From: Martin Storsjö @ 2022-02-25 9:13 UTC (permalink / raw) To: FFmpeg development discussions and patches On Thu, 24 Feb 2022, Michael Niedermayer wrote: > On Wed, Feb 23, 2022 at 09:45:53PM +0200, Martin Storsjö wrote: >> 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 > > LGTM > > tested on mingw32/64 + wine / linux x86 32/64bit, arm/mips qemu Thanks, pushed! // Martin _______________________________________________ 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". ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-25 9:13 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-02-18 14:45 [FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions Martin Storsjö 2022-02-19 15:48 ` Michael Niedermayer 2022-02-19 21:43 ` Martin Storsjö 2022-02-23 19:45 ` [FFmpeg-devel] [PATCH v2] " Martin Storsjö 2022-02-24 22:50 ` Michael Niedermayer 2022-02-25 9:13 ` Martin Storsjö
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