]> git.sesse.net Git - mlt/blobdiff - src/modules/core/producer_colour.c
Producer color hack for Movit.
[mlt] / src / modules / core / producer_colour.c
index ad2a5ae092aca3a1c1da95e27e6f07a1ba241d7e..0121689ec1b57c86c7080681b8d4d91f66f3478c 100644 (file)
@@ -48,9 +48,9 @@ mlt_producer producer_colour_init( mlt_profile profile, mlt_service_type type, c
                producer->close = ( mlt_destructor )producer_close;
 
                // Set the default properties
-               mlt_properties_set( properties, "resource", colour == NULL ? "0x000000ff" : colour );
+               mlt_properties_set( properties, "resource", ( !colour || !strcmp( colour, "" ) ) ? "0x000000ff" : colour );
                mlt_properties_set( properties, "_resource", "" );
-               mlt_properties_set_double( properties, "aspect_ratio", 0 );
+               mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
                
                return producer;
        }
@@ -80,6 +80,12 @@ rgba_color parse_color( char *color, unsigned int color_int )
                result.g = 0x00;
                result.b = 0xff;
        }
+       else if ( !strcmp( color, "black" ) )
+       {
+               result.r = 0x00;
+               result.g = 0x00;
+               result.b = 0x00;
+       }
        else if ( strcmp( color, "white" ) )
        {
                result.r = ( color_int >> 24 ) & 0xff;
@@ -99,6 +105,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Obtain the producer for this frame
        mlt_producer producer = mlt_properties_get_data( properties, "producer_colour", NULL );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
+
        // Obtain properties of producer
        mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
 
@@ -116,11 +124,21 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Parse the colour
        if ( now && strchr( now, '/' ) )
        {
-               now = strrchr( now, '/' ) + 1;
+               now = strdup( strrchr( now, '/' ) + 1 );
                mlt_properties_set( producer_props, "resource", now );
+               free( now );
+               now = mlt_properties_get( producer_props, "resource" );
        }
        rgba_color color = parse_color( now, mlt_properties_get_int( producer_props, "resource" ) );
 
+       // Choose suitable out values if nothing specific requested
+       if ( *format == mlt_image_none )
+               *format = mlt_image_rgb24a;
+       if ( *width <= 0 )
+               *width = mlt_service_profile( MLT_PRODUCER_SERVICE(producer) )->width;
+       if ( *height <= 0 )
+               *height = mlt_service_profile( MLT_PRODUCER_SERVICE(producer) )->height;
+
        // See if we need to regenerate
        if ( strcmp( now, then ) || *width != current_width || *height != current_height || *format != current_format )
        {
@@ -128,23 +146,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                int i = *width * *height + 1;
                int bpp;
 
-               switch ( *format )
-               {
-                       case mlt_image_rgb24:
-                               bpp = 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               bpp = 4;
-                               break;
-                       default:
-                               bpp = 2;
-                               *format = mlt_image_yuv422;
-                               break;
-               }
-
                // Allocate the image
-               size = *width * *height * bpp;
+               size = mlt_image_format_size( *format, *width, *height, &bpp );
                uint8_t *p = image = mlt_pool_alloc( size );
 
                // Update the producer
@@ -154,6 +157,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                mlt_properties_set_int( producer_props, "_format", *format );
                mlt_properties_set( producer_props, "_resource", now );
 
+               mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
+
                switch ( *format )
                {
                case mlt_image_yuv422:
@@ -162,7 +167,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                        int count = ( *width - uneven ) / 2 + 1;
                        uint8_t y, u, v;
 
-                       RGB2YUV( color.r, color.g, color.b, y, u, v );
+                       RGB2YUV_601_SCALED( color.r, color.g, color.b, y, u, v );
                        i = *height + 1;
                        while ( --i )
                        {
@@ -190,8 +195,12 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                *p ++ = color.b;
                        }
                        break;
-               case mlt_image_rgb24a:
-               case mlt_image_opengl:
+               case mlt_image_glsl:
+               case mlt_image_glsl_texture:
+                       memset(p, 0, size);
+                       break;
+               default:
+                       *format = mlt_image_rgb24a;
                        while ( --i )
                        {
                                *p ++ = color.r;
@@ -200,10 +209,12 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                *p ++ = color.a;
                        }
                        break;
-               default:
-                       break;
                }
        }
+       else
+       {
+               mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
+       }
 
        // Create the alpha channel
        int alpha_size = *width * *height;
@@ -218,9 +229,12 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        memcpy( *buffer, image, size );
 
        // Now update properties so we free the copy after
-       mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
-       mlt_properties_set_data( properties, "alpha", alpha, alpha_size, mlt_pool_release, NULL );
+       mlt_frame_set_image( frame, *buffer, size, mlt_pool_release );
+       mlt_frame_set_alpha( frame, alpha, alpha_size, mlt_pool_release );
        mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
+       mlt_properties_set_int( properties, "meta.media.width", *width );
+       mlt_properties_set_int( properties, "meta.media.height", *height );
+
 
        return 0;
 }
@@ -246,7 +260,8 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", 1 );
-               mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
+               mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) );
+               mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
 
                // colour is an alias for resource
                if ( mlt_properties_get( producer_props, "colour" ) != NULL )