]> git.sesse.net Git - mlt/commitdiff
Get initial skipping of luma scaling to work.
authorDan Dennedy <dan@dennedy.org>
Tue, 24 Aug 2010 07:24:25 +0000 (00:24 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 26 Sep 2010 22:20:15 +0000 (15:20 -0700)
When the avformat producer property skip_luma_scale is set to 1, then we
do not scale the luma on the first YCbCr to RGB conversion. This is only
done once because swscale always downscales luma when converting RGB to
YCbCr, and we need to keep the conversions symmetrical to prevent luma
contraction (loss of contrast).

src/modules/avformat/filter_avcolour_space.c
src/modules/avformat/producer_avformat.c

index c1f6b203f365c7a4c0c28574fb1778b9cde1ab1e..392485b887ff07d2d16f3f73500491528093325a 100644 (file)
@@ -75,48 +75,27 @@ static int convert_mlt_to_av_cs( mlt_image_format format )
        return value;
 }
 
-enum luma_scale {
-       LUMA_SCALE_AUTO = 0,
-       LUMA_SCALE_NONE,
-       LUMA_SCALE_OUT,
-       LUMA_SCALE_IN
-};
-
-static void set_luma_transfer( struct SwsContext *context, int is_709, enum luma_scale scale )
+static void set_luma_transfer( struct SwsContext *context, int is_709, int no_scale )
 {
        int *coefficients;
-       int range_in, range_out;
+       int range;
        int brightness, contrast, saturation;
 
-       if ( sws_getColorspaceDetails( context, &coefficients, &range_in, &coefficients, &range_out,
+       if ( sws_getColorspaceDetails( context, &coefficients, &range, &coefficients, &range,
                        &brightness, &contrast, &saturation ) != -1 )
        {
                // Don't change these from defaults unless explicitly told to.
-               switch ( scale )
-               {
-               case LUMA_SCALE_NONE:
-                       range_in = range_out = 1;
-                       break;
-               case LUMA_SCALE_OUT:
-                       range_in = 0;
-                       range_out = 1;
-                       break;
-               case LUMA_SCALE_IN:
-                       range_in = 1;
-                       range_out = 0;
-                       break;
-               default:
-                       break;
-               }
+               if ( no_scale )
+                       range = 1;
                if ( is_709 )
                        coefficients = sws_getCoefficients( SWS_CS_ITU709 );
-               sws_setColorspaceDetails( context, coefficients, range_in, coefficients, range_out,
+               sws_setColorspaceDetails( context, coefficients, range, coefficients, range,
                        brightness, contrast, saturation );
        }
 }
 
 static void av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt,
-       int width, int height, int is_709, int is_full )
+       int width, int height, int is_709, int no_scale )
 {
        AVPicture input;
        AVPicture output;
@@ -138,7 +117,7 @@ static void av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt
 #ifdef SWSCALE
        struct SwsContext *context = sws_getContext( width, height, in_fmt,
                width, height, out_fmt, flags, NULL, NULL, NULL);
-       set_luma_transfer( context, is_709, is_full );
+       set_luma_transfer( context, is_709, no_scale );
        sws_scale( context, input.data, input.linesize, 0, height,
                output.data, output.linesize);
        sws_freeContext( context );
@@ -200,8 +179,14 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
 
                // Update the output
                int is_709 = output_format == mlt_image_yuv422 && width * height > 750000;
-               enum luma_scale luma = LUMA_SCALE_AUTO;
-               av_convert_image( output, *image, out_fmt, in_fmt, width, height, is_709, luma );
+               int no_scale_luma = 0;
+               if ( *format == mlt_image_yuv422 && mlt_properties_get_int( properties, "skip_luma_scale" )
+                        && ( output_format == mlt_image_rgb24 || output_format == mlt_image_rgb24a ) )
+               {
+                       no_scale_luma = 1;
+                       mlt_properties_set( properties, "skip_luma_scale", NULL );
+               }
+               av_convert_image( output, *image, out_fmt, in_fmt, width, height, is_709, no_scale_luma );
                *image = output;
                *format = output_format;
                mlt_properties_set_data( properties, "image", output, size, mlt_pool_release, NULL );
index a17e833f026d742f085fa36fd34c5ac029e68b5c..72daaf4e23f0d83bdf33e82a9bf84a4b67804c47 100644 (file)
@@ -690,42 +690,21 @@ static void get_audio_streams_info( producer_avformat this )
 }
 
 #ifdef SWSCALE
-enum luma_scale {
-       LUMA_SCALE_AUTO = 0,
-       LUMA_SCALE_NONE,
-       LUMA_SCALE_OUT,
-       LUMA_SCALE_IN
-};
-
-static void set_luma_transfer( struct SwsContext *context, int is_709, enum luma_scale scale )
+static void set_luma_transfer( struct SwsContext *context, int is_709, int no_scale )
 {
        int *coefficients;
-       int range_in, range_out;
+       int range;
        int brightness, contrast, saturation;
 
-       if ( sws_getColorspaceDetails( context, &coefficients, &range_in, &coefficients, &range_out,
+       if ( sws_getColorspaceDetails( context, &coefficients, &range, &coefficients, &range,
                        &brightness, &contrast, &saturation ) != -1 )
        {
                // Don't change these from defaults unless explicitly told to.
-               switch ( scale )
-               {
-               case LUMA_SCALE_NONE:
-                       range_in = range_out = 1;
-                       break;
-               case LUMA_SCALE_OUT:
-                       range_in = 0;
-                       range_out = 1;
-                       break;
-               case LUMA_SCALE_IN:
-                       range_in = 1;
-                       range_out = 0;
-                       break;
-               default:
-                       break;
-               }
+               if ( no_scale )
+                       range = 1;
                if ( is_709 )
                        coefficients = sws_getCoefficients( SWS_CS_ITU709 );
-               sws_setColorspaceDetails( context, coefficients, range_in, coefficients, range_out,
+               sws_setColorspaceDetails( context, coefficients, range, coefficients, range,
                        brightness, contrast, saturation );
        }
 }
@@ -735,7 +714,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
 {
 #ifdef SWSCALE
        int is_709 = *format == mlt_image_yuv422 && width * height > 750000;
-       enum luma_scale luma = LUMA_SCALE_AUTO;
+       int luma = 0;
        int flags = SWS_BILINEAR | SWS_ACCURATE_RND;
 
 #ifdef USE_MMX
@@ -779,6 +758,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
                        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 );
+               luma = 1;
                set_luma_transfer( context, is_709, luma );
                sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
@@ -790,6 +770,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
                        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 );
+               luma = 1;
                set_luma_transfer( context, is_709, luma );
                sws_scale( context, frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
@@ -1339,6 +1320,9 @@ exit_get_image:
        else
                mlt_properties_set_int( frame_properties, "top_field_first", this->top_field_first );
 
+       if ( *format == mlt_image_yuv422 && mlt_properties_get( properties, "skip_luma_scale" ) )
+               mlt_properties_set_int( frame_properties, "skip_luma_scale", 1 );
+
        return !this->got_picture;
 }