diff mbox series

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

Message ID 20220218144546.43231-1-martin@martin.st
State New
Headers show
Series [FFmpeg-devel] swscale: Take the destination range into account for yuv->rgb->yuv conversions | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Martin Storsjö Feb. 18, 2022, 2:45 p.m. UTC
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(-)

Comments

Michael Niedermayer Feb. 19, 2022, 3:48 p.m. UTC | #1
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

[...]
Martin Storsjö Feb. 19, 2022, 9:43 p.m. UTC | #2
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
diff mbox series

Patch

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);