From 4fd6c14958ac5bd739c8d2b66b86cbf99ae68c23 Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Wed, 19 Feb 2014 23:43:50 -0800 Subject: [PATCH] Fix YUV to RGB conversion when profile colorspace not 601. The non-default coefficients for RGB cause incorrect conversion. Reported by Claus R. F. Overbeck on the kdenlive-devel mailing list. --- src/modules/avformat/filter_avcolour_space.c | 5 ++++- src/modules/avformat/producer_avformat.c | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/avformat/filter_avcolour_space.c b/src/modules/avformat/filter_avcolour_space.c index 5733aa82..cce62c5e 100644 --- a/src/modules/avformat/filter_avcolour_space.c +++ b/src/modules/avformat/filter_avcolour_space.c @@ -1,6 +1,6 @@ /* * filter_avcolour_space.c -- Colour space filter - * Copyright (C) 2004-2005 Ushodaya Enterprises Limited + * Copyright (C) 2004-2014 Ushodaya Enterprises Limited * Author: Charles Yates * * This library is free software; you can redistribute it and/or @@ -143,6 +143,9 @@ static int av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt, width, height, out_fmt, flags, NULL, NULL, NULL); if ( context ) { + // libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601. + if ( out_fmt == PIX_FMT_RGB24 || out_fmt == PIX_FMT_RGBA ) + dst_colorspace = 601; error = set_luma_transfer( context, src_colorspace, dst_colorspace, use_full_range ); sws_scale( context, (const uint8_t* const*) input.data, input.linesize, 0, height, output.data, output.linesize); diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index cbdd38fd..be1cc06e 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -1,6 +1,6 @@ /* * producer_avformat.c -- avformat producer - * Copyright (C) 2003-2012 Ushodaya Enterprises Limited + * Copyright (C) 2003-2014 Ushodaya Enterprises Limited * Author: Charles Yates * Author: Dan Dennedy * Much code borrowed from ffmpeg.c: Copyright (c) 2000-2003 Fabrice Bellard @@ -1189,7 +1189,8 @@ static int convert_image( producer_avformat self, AVFrame *frame, uint8_t *buffe width, height, PIX_FMT_RGB24, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL); AVPicture output; avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height ); - set_luma_transfer( context, self->yuv_colorspace, profile->colorspace, self->full_luma ); + // libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601. + set_luma_transfer( context, self->yuv_colorspace, 601, self->full_luma ); sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height, output.data, output.linesize); sws_freeContext( context ); @@ -1200,7 +1201,8 @@ static int convert_image( producer_avformat self, AVFrame *frame, uint8_t *buffe width, height, PIX_FMT_RGBA, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL); AVPicture output; avpicture_fill( &output, buffer, PIX_FMT_RGBA, width, height ); - set_luma_transfer( context, self->yuv_colorspace, profile->colorspace, self->full_luma ); + // libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601. + set_luma_transfer( context, self->yuv_colorspace, 601, self->full_luma ); sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height, output.data, output.linesize); sws_freeContext( context ); -- 2.39.2