]> git.sesse.net Git - mlt/commitdiff
More fixes for force_full_luma (kdenlive-2799).
authorDan Dennedy <dan@dennedy.org>
Mon, 12 Nov 2012 01:10:28 +0000 (17:10 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 12 Nov 2012 01:10:28 +0000 (17:10 -0800)
This change lets the image converter downstream of the avformat producer
perform utilize the range as-needed. Then, when the rescale filter sees
that the force_full_range is set on the frame but has not yet been
applied, forces a conversion to RGB to enforce it. In addition, the
recently added force_full_luma property on the avformat producer is
removed because it is redundant with AVOption color_range=2.

src/modules/avformat/producer_avformat.c
src/modules/avformat/producer_avformat.yml
src/modules/core/filter_resize.c

index 3e0f85a5a04cc0c3e3658a23885023c404c6e2e5..1d21431921997b7d0694f36ff4080d5d05e8a4c5 100644 (file)
@@ -1289,7 +1289,7 @@ static void convert_image( producer_avformat self, AVFrame *frame, uint8_t *buff
                output.linesize[0] = width;
                output.linesize[1] = width >> 1;
                output.linesize[2] = width >> 1;
-               set_luma_transfer( context, self->colorspace, self->full_luma );
+               set_luma_transfer( context, self->colorspace, -1 );
                sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
                sws_freeContext( context );
@@ -1322,7 +1322,7 @@ static void convert_image( producer_avformat self, AVFrame *frame, uint8_t *buff
                        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 );
-               set_luma_transfer( context, self->colorspace, self->full_luma );
+               set_luma_transfer( context, self->colorspace, -1 );
                sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height,
                        output.data, output.linesize);
                sws_freeContext( context );
@@ -1789,6 +1789,11 @@ exit_get_image:
        mlt_properties_set_int( properties, "meta.media.progressive", mlt_properties_get_int( frame_properties, "progressive" ) );
        mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
 
+       // If we already have RGB, then the full range processing either happened already
+       // or does not apply (RGB source).
+       if ( *format == mlt_image_rgb24 || *format == mlt_image_rgb24a || *format == mlt_image_opengl )
+               mlt_properties_set( frame_properties, "force_full_luma", NULL );
+
        return !got_picture;
 }
 
@@ -1983,13 +1988,10 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p
 #if LIBAVCODEC_VERSION_INT >= ((52<<16)+(72<<8)+2)
                mlt_log_debug( MLT_PRODUCER_SERVICE(self->parent), "color_range %d\n", codec_context->color_range );
                if ( codec_context->color_range == AVCOL_RANGE_JPEG )
-                       self->full_luma = 1;
+                       mlt_properties_set_int( properties, "set.force_full_luma", 1 );
 #endif
-               if ( mlt_properties_get( properties, "force_full_luma" ) )
-                       self->full_luma = mlt_properties_get_int( properties, "force_full_luma" );
-               else if ( mlt_properties_get( properties, "set.force_full_luma" ) )
+               if ( mlt_properties_get( properties, "set.force_full_luma" ) )
                        self->full_luma = mlt_properties_get_int( properties, "set.force_full_luma" );
-               mlt_properties_set( properties, "set.force_full_luma", NULL );
        }
        return self->video_codec && self->video_index > -1;
 }
index 632aa0ef1b0d94b1da2d8097395600070dcbd27c..f789835397291f9bcb21661447b27eee754962d9 100644 (file)
@@ -175,15 +175,3 @@ parameters:
     default: 0
     unit: seconds
     widget: timecode
-
-  - identifier: force_full_luma
-    title: Use full range
-    description: >
-      When converting from Y'CbCr to RGB, normally the range specified by the
-      decoder is used. For MPEG and many codings, the luma range is scaled from
-      [16, 235] to [0, 255] in RGB. When provided, this property overrides the
-      detected range of the video.
-    type: integer
-    minimum: 0
-    maximum: 1
-    widget: checkbox
index d3e4ca344632738e9bdfe7cf8e3838bb7d75ef30..06e5b9a0001566d40fd89b3293ecfa0456b1d2be 100644 (file)
@@ -202,6 +202,13 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Reset the aspect ratio
        mlt_properties_set_double( properties, "aspect_ratio", aspect_ratio );
 
+       // XXX: This is a hack, but it forces the force_full_luma to apply by doing a RGB
+       // conversion because range scaling only occurs on YUV->RGB. And we do it here,
+       // after the deinterlace filter, which only operates in YUV to avoid a YUV->RGB->YUV->?.
+       // Instead, it will go YUV->RGB->?.
+       if ( mlt_properties_get_int( properties, "force_full_luma" ) )
+               *format = mlt_image_rgb24a;
+
        // Hmmm...
        char *rescale = mlt_properties_get( properties, "rescale.interp" );
        if ( rescale != NULL && !strcmp( rescale, "none" ) )