]> git.sesse.net Git - mlt/blobdiff - src/modules/core/producer_colour.c
Fix crashing when using opengl services with wrapper producers.
[mlt] / src / modules / core / producer_colour.c
index 03c41a2b6404595c92e345292e54a41444941cf7..80ca7a61b79e97ca4afe687bb5d6cc44845747ce 100644 (file)
 #include <string.h>
 
 
-typedef struct
-{
-       uint8_t r, g, b, a;
-} rgba_color;
-
 static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
 static void producer_close( mlt_producer parent );
 
@@ -48,7 +43,7 @@ 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", mlt_profile_sar( profile ) );
                
@@ -58,39 +53,6 @@ mlt_producer producer_colour_init( mlt_profile profile, mlt_service_type type, c
        return NULL;
 }
 
-rgba_color parse_color( char *color, unsigned int color_int )
-{
-       rgba_color result = { 0xff, 0xff, 0xff, 0xff };
-
-       if ( !strcmp( color, "red" ) )
-       {
-               result.r = 0xff;
-               result.g = 0x00;
-               result.b = 0x00;
-       }
-       else if ( !strcmp( color, "green" ) )
-       {
-               result.r = 0x00;
-               result.g = 0xff;
-               result.b = 0x00;
-       }
-       else if ( !strcmp( color, "blue" ) )
-       {
-               result.r = 0x00;
-               result.g = 0x00;
-               result.b = 0xff;
-       }
-       else if ( strcmp( color, "white" ) )
-       {
-               result.r = ( color_int >> 24 ) & 0xff;
-               result.g = ( color_int >> 16 ) & 0xff;
-               result.b = ( color_int >> 8 ) & 0xff;
-               result.a = ( color_int ) & 0xff;
-       }
-
-       return result;
-}
-
 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
 {
        // Obtain properties of frame
@@ -118,10 +80,20 @@ 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" ) );
+       mlt_color color = mlt_properties_get_color( producer_props, "resource" );
+
+       // Choose suitable out values if nothing specific requested
+       if ( *format == mlt_image_none || *format == mlt_image_glsl )
+               *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 )
@@ -130,23 +102,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
@@ -194,8 +151,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;
@@ -204,8 +165,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                *p ++ = color.a;
                        }
                        break;
-               default:
-                       break;
                }
        }
        else
@@ -229,8 +188,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        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, "real_width", *width );
-       mlt_properties_set_int( properties, "real_height", *height );
+       mlt_properties_set_int( properties, "meta.media.width", *width );
+       mlt_properties_set_int( properties, "meta.media.height", *height );
 
 
        return 0;
@@ -257,7 +216,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 )