]> git.sesse.net Git - mlt/commitdiff
Improve quality of libswscale conversions and scaling.
authorDan Dennedy <dan@dennedy.org>
Sat, 14 Aug 2010 07:55:24 +0000 (00:55 -0700)
committerDan Dennedy <dan@dennedy.org>
Sat, 14 Aug 2010 07:55:24 +0000 (00:55 -0700)
src/modules/avformat/consumer_avformat.c
src/modules/avformat/filter_avcolour_space.c
src/modules/avformat/filter_swscale.c
src/modules/avformat/producer_avformat.c

index db63b487289fdfa1ed601c7e175bbfe30a8e4bb1..22c52a9ba251e85ceaa814cb4687054ece80eb42 100644 (file)
@@ -1283,7 +1283,7 @@ static void *consumer_thread( void *arg )
                                                // Do the colour space conversion
 #ifdef SWSCALE
                                                struct SwsContext *context = sws_getContext( width, height, PIX_FMT_YUYV422,
-                                                       width, height, video_st->codec->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+                                                       width, height, video_st->codec->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL);
                                                sws_scale( context, input->data, input->linesize, 0, height,
                                                        output->data, output->linesize);
                                                sws_freeContext( context );
index b1c5eb6254d082b7df88463f7f977e05f1305f66..d64841ecde5afe8e6122cfc9122235e6d64a6488 100644 (file)
@@ -76,11 +76,18 @@ static void av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt
 {
        AVPicture input;
        AVPicture output;
+       int flags = SWS_BILINEAR | SWS_ACCURATE_RND;
+
+       if ( out_fmt == PIX_FMT_YUYV422 )
+               flags |= SWS_FULL_CHR_H_INP;
+       else
+               flags |= SWS_FULL_CHR_H_INT;
+
        avpicture_fill( &input, in, in_fmt, width, height );
        avpicture_fill( &output, out, out_fmt, width, height );
 #ifdef SWSCALE
        struct SwsContext *context = sws_getContext( width, height, in_fmt,
-               width, height, out_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+               width, height, out_fmt, flags, NULL, NULL, NULL);
        sws_scale( context, input.data, input.linesize, 0, height,
                output.data, output.linesize);
        sws_freeContext( context );
index f9c23e55792c3f7359492ec89df3c3e16b9f0762..c841928ac9ece01515f1d413add51990c1e456a4 100644 (file)
@@ -92,6 +92,7 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                interp = SWS_LANCZOS;
        else if ( strcmp( interps, "spline" ) == 0 )
                interp = SWS_SPLINE;
+       interp |= SWS_ACCURATE_RND;
 
        // Determine the bytes per pixel
        int bpp;
@@ -99,13 +100,16 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        {
                case mlt_image_yuv422:
                        bpp = 2;
+                       interp |= SWS_FULL_CHR_H_INP;
                        break;
                case mlt_image_rgb24:
                        bpp = 3;
+                       interp |= SWS_FULL_CHR_H_INT;
                        break;
                case mlt_image_rgb24a:
                case mlt_image_opengl:
                        bpp = 4;
+                       interp |= SWS_FULL_CHR_H_INT;
                        break;
                default:
                        // XXX: we only know how to rescale packed formats
index ba323ec00c82a2ecd63b4f96be328ed97accdb1b..1217c29ffb07e875046d123bfcd935ebfc187c87 100644 (file)
@@ -679,11 +679,12 @@ static void get_audio_streams_info( producer_avformat this )
 static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format *format, int width, int height )
 {
 #ifdef SWSCALE
+       int flags = SWS_BILINEAR | SWS_ACCURATE_RND;
        if ( pix_fmt == PIX_FMT_RGB32 )
        {
                *format = mlt_image_rgb24a;
                struct SwsContext *context = sws_getContext( width, height, pix_fmt,
-                       width, height, PIX_FMT_RGBA, SWS_BILINEAR, NULL, NULL, NULL);
+                       width, height, PIX_FMT_RGBA, flags, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_RGBA, width, height );
                sws_scale( context, frame->data, frame->linesize, 0, height,
@@ -693,7 +694,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
        else if ( *format == mlt_image_yuv420p )
        {
                struct SwsContext *context = sws_getContext( width, height, pix_fmt,
-                       width, height, PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL);
+                       width, height, PIX_FMT_YUV420P, flags, NULL, NULL, NULL);
                AVPicture output;
                output.data[0] = buffer;
                output.data[1] = buffer + width * height;
@@ -708,7 +709,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
        else if ( *format == mlt_image_rgb24 )
        {
                struct SwsContext *context = sws_getContext( width, height, pix_fmt,
-                       width, height, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL);
+                       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 );
                sws_scale( context, frame->data, frame->linesize, 0, height,
@@ -718,7 +719,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
        else if ( *format == mlt_image_rgb24a || *format == mlt_image_opengl )
        {
                struct SwsContext *context = sws_getContext( width, height, pix_fmt,
-                       width, height, PIX_FMT_RGBA, SWS_BILINEAR, NULL, NULL, NULL);
+                       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 );
                sws_scale( context, frame->data, frame->linesize, 0, height,
@@ -728,7 +729,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
        else
        {
                struct SwsContext *context = sws_getContext( width, height, pix_fmt,
-                       width, height, PIX_FMT_YUYV422, SWS_BILINEAR, NULL, NULL, NULL);
+                       width, height, PIX_FMT_YUYV422, flags | SWS_FULL_CHR_H_INP, NULL, NULL, NULL);
                AVPicture output;
                avpicture_fill( &output, buffer, PIX_FMT_YUYV422, width, height );
                sws_scale( context, frame->data, frame->linesize, 0, height,