X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Fproducer_colour.c;h=0121689ec1b57c86c7080681b8d4d91f66f3478c;hb=44ceaed3162eb0004c56d1921807ef24bf8adb21;hp=7eeaac74b4ce111fb1186d6773130f6c184de5f0;hpb=bf3264b9e340ba5c11cbf59835a8af3db94e0cc2;p=mlt diff --git a/src/modules/core/producer_colour.c b/src/modules/core/producer_colour.c index 7eeaac74..0121689e 100644 --- a/src/modules/core/producer_colour.c +++ b/src/modules/core/producer_colour.c @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "producer_colour.h" +#include #include #include @@ -35,7 +35,7 @@ typedef struct static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index ); static void producer_close( mlt_producer parent ); -mlt_producer producer_colour_init( char *colour ) +mlt_producer producer_colour_init( mlt_profile profile, mlt_service_type type, const char *id, char *colour ) { mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) ); if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 ) @@ -48,9 +48,9 @@ mlt_producer producer_colour_init( char *colour ) 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; } @@ -58,23 +58,11 @@ mlt_producer producer_colour_init( char *colour ) return NULL; } -rgba_color parse_color( char *color ) +rgba_color parse_color( char *color, unsigned int color_int ) { rgba_color result = { 0xff, 0xff, 0xff, 0xff }; - if ( strchr( color, '/' ) ) - color = strrchr( color, '/' ) + 1; - - if ( !strncmp( color, "0x", 2 ) ) - { - unsigned int temp = 0; - sscanf( color + 2, "%x", &temp ); - result.r = ( temp >> 24 ) & 0xff; - result.g = ( temp >> 16 ) & 0xff; - result.b = ( temp >> 8 ) & 0xff; - result.a = ( temp ) & 0xff; - } - else if ( !strcmp( color, "red" ) ) + if ( !strcmp( color, "red" ) ) { result.r = 0xff; result.g = 0x00; @@ -92,14 +80,18 @@ rgba_color parse_color( char *color ) 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" ) ) { - unsigned int temp = 0; - sscanf( color, "%d", &temp ); - result.r = ( temp >> 24 ) & 0xff; - result.g = ( temp >> 16 ) & 0xff; - result.b = ( temp >> 8 ) & 0xff; - result.a = ( temp ) & 0xff; + 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; @@ -107,15 +99,14 @@ rgba_color parse_color( char *color ) static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) { - // May need to know the size of the image to clone it - int size = 0; - // Obtain properties of frame mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); // 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 ); @@ -124,86 +115,126 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form char *then = mlt_properties_get( producer_props, "_resource" ); // Get the current image and dimensions cached in the producer + int size = 0; uint8_t *image = mlt_properties_get_data( producer_props, "image", &size ); int current_width = mlt_properties_get_int( producer_props, "_width" ); int current_height = mlt_properties_get_int( producer_props, "_height" ); + mlt_image_format current_format = mlt_properties_get_int( producer_props, "_format" ); // Parse the colour - rgba_color color = parse_color( now ); + if ( now && strchr( now, '/' ) ) + { + 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 ) + if ( strcmp( now, then ) || *width != current_width || *height != current_height || *format != current_format ) { // Color the image - uint8_t y, u, v; - int i = *height; - int j = 0; - int uneven = *width % 2; - int count = ( *width - uneven ) / 2; - uint8_t *p = NULL; + int i = *width * *height + 1; + int bpp; // Allocate the image - size = *width * *height * 2; - image = mlt_pool_alloc( size ); + size = mlt_image_format_size( *format, *width, *height, &bpp ); + uint8_t *p = image = mlt_pool_alloc( size ); // Update the producer mlt_properties_set_data( producer_props, "image", image, size, mlt_pool_release, NULL ); mlt_properties_set_int( producer_props, "_width", *width ); mlt_properties_set_int( producer_props, "_height", *height ); + mlt_properties_set_int( producer_props, "_format", *format ); mlt_properties_set( producer_props, "_resource", now ); - RGB2YUV( color.r, color.g, color.b, y, u, v ); - - p = image; + mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) ); - while ( i -- ) + switch ( *format ) { - j = count; - while ( j -- ) + case mlt_image_yuv422: + { + int uneven = *width % 2; + int count = ( *width - uneven ) / 2 + 1; + uint8_t y, u, v; + + RGB2YUV_601_SCALED( color.r, color.g, color.b, y, u, v ); + i = *height + 1; + while ( --i ) + { + int j = count; + while ( --j ) + { + *p ++ = y; + *p ++ = u; + *p ++ = y; + *p ++ = v; + } + if ( uneven ) + { + *p ++ = y; + *p ++ = u; + } + } + break; + } + case mlt_image_rgb24: + while ( --i ) { - *p ++ = y; - *p ++ = u; - *p ++ = y; - *p ++ = v; + *p ++ = color.r; + *p ++ = color.g; + *p ++ = color.b; } - if ( uneven ) + break; + case mlt_image_glsl: + case mlt_image_glsl_texture: + memset(p, 0, size); + break; + default: + *format = mlt_image_rgb24a; + while ( --i ) { - *p ++ = y; - *p ++ = u; + *p ++ = color.r; + *p ++ = color.g; + *p ++ = color.b; + *p ++ = color.a; } + break; } } - - // Update the frame - mlt_properties_set_int( properties, "width", *width ); - mlt_properties_set_int( properties, "height", *height ); - - // Clone if necessary (deemed always necessary) - if ( 1 ) + else { - // Create the alpha channel - uint8_t *alpha = mlt_pool_alloc( size >> 1 ); + mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) ); + } - // Clone our image - uint8_t *copy = mlt_pool_alloc( size ); - memcpy( copy, image, size ); + // Create the alpha channel + int alpha_size = *width * *height; + uint8_t *alpha = mlt_pool_alloc( alpha_size ); - // We're going to pass the copy on - image = copy; + // Initialise the alpha + if ( alpha ) + memset( alpha, color.a, alpha_size ); - // Initialise the alpha - if ( alpha ) - memset( alpha, color.a, size >> 1 ); + // Clone our image + *buffer = mlt_pool_alloc( size ); + memcpy( *buffer, image, size ); - // Now update properties so we free the copy after - mlt_properties_set_data( properties, "image", copy, size, mlt_pool_release, NULL ); - mlt_properties_set_data( properties, "alpha", alpha, size >> 1, mlt_pool_release, NULL ); - mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) ); - } + // Now update properties so we free the copy after + 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 ); - // Pass on the image - *buffer = image; - *format = mlt_image_yuv422; return 0; } @@ -211,7 +242,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) { // Generate a frame - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); if ( *frame != NULL ) { @@ -229,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 )