From b41fc3efd457b709d4f9867273f6d0da8921b904 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Sat, 12 Feb 2005 13:20:35 +0000 Subject: [PATCH] Alphas and global feeds revisted git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@666 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_producer.c | 4 +-- src/framework/mlt_tractor.c | 2 +- src/modules/core/producer_colour.c | 12 ++++++++- src/modules/core/transition_composite.c | 35 ++++++++++++++++++++----- src/modules/feeds/PAL/etv.properties | 12 ++++----- src/modules/gtk2/producer_pango.c | 11 ++++---- src/modules/plus/filter_affine.c | 1 + src/modules/plus/transition_affine.c | 27 ++++++++++++++----- src/modules/sdl/consumer_sdl_preview.c | 9 +++---- src/modules/westley/consumer_westley.c | 2 +- src/modules/westley/producer_westley.c | 2 ++ 11 files changed, 81 insertions(+), 36 deletions(-) diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index 55f85ada..1b86f6c9 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -194,8 +194,8 @@ mlt_producer mlt_producer_cut( mlt_producer this, int in, int out ) // Special case - allow for a cut of the entire producer (this will squeeze all other cuts to 0) if ( in <= 0 ) in = 0; - if ( ( out < 0 || out >= mlt_producer_get_playtime( parent ) ) && !mlt_producer_is_blank( this ) ) - out = mlt_producer_get_playtime( parent ) - 1; + if ( ( out < 0 || out >= mlt_producer_get_length( parent ) ) && !mlt_producer_is_blank( this ) ) + out = mlt_producer_get_length( parent ) - 1; mlt_properties_inc_ref( parent_props ); mlt_properties_set_int( properties, "_cut", 1 ); diff --git a/src/framework/mlt_tractor.c b/src/framework/mlt_tractor.c index ffc47797..7eb43c52 100644 --- a/src/framework/mlt_tractor.c +++ b/src/framework/mlt_tractor.c @@ -332,7 +332,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra // Move the contents of this queue on to the output frames data queue mlt_deque sub_queue = mlt_properties_get_data( MLT_FRAME_PROPERTIES( temp ), "data_queue", NULL ); mlt_deque temp = mlt_deque_init( ); - while ( mlt_deque_count( sub_queue ) ) + while ( global_feed && mlt_deque_count( sub_queue ) ) { mlt_properties p = mlt_deque_pop_back( sub_queue ); if ( mlt_properties_get_int( p, "final" ) ) diff --git a/src/modules/core/producer_colour.c b/src/modules/core/producer_colour.c index 0c40f99b..f7966ed8 100644 --- a/src/modules/core/producer_colour.c +++ b/src/modules/core/producer_colour.c @@ -117,6 +117,9 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Obtain properties of producer mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); + // Parse the colour + rgba_color color = parse_color( mlt_properties_get( producer_props, "resource" ) ); + // Get the current image and dimensions cached in the producer uint8_t *image = mlt_properties_get_data( producer_props, "image", &size ); int current_width = mlt_properties_get_int( producer_props, "width" ); @@ -135,7 +138,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form mlt_properties_set_int( producer_props, "height", *height ); // Color the image - rgba_color color = parse_color( mlt_properties_get( producer_props, "resource" ) ); uint8_t y, u, v; int i = 0; RGB2YUV( color.r, color.g, color.b, y, u, v ); @@ -157,6 +159,9 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Clone if necessary if ( writable ) { + // Create the alpha channel + uint8_t *alpha = mlt_pool_alloc( size >> 1 ); + // Clone our image uint8_t *copy = mlt_pool_alloc( size ); memcpy( copy, image, size ); @@ -164,8 +169,13 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // We're going to pass the copy on image = copy; + // Initialise the alpha + if ( alpha ) + memset( alpha, color.a, size >> 1 ); + // 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 ); } // Pass on the image diff --git a/src/modules/core/transition_composite.c b/src/modules/core/transition_composite.c index 6b55405b..aafdd17b 100644 --- a/src/modules/core/transition_composite.c +++ b/src/modules/core/transition_composite.c @@ -27,7 +27,7 @@ #include #include -typedef void ( *composite_line_fn )( uint8_t *dest, uint8_t *src, int width_src, uint8_t *alpha, int weight, uint16_t *luma, int softness ); +typedef void ( *composite_line_fn )( uint8_t *dest, uint8_t *src, int width_src, uint8_t *alpha, uint8_t *full_alpha, int weight, uint16_t *luma, int softness ); /* mmx function declarations */ #ifdef USE_MMX @@ -381,7 +381,7 @@ static void luma_read_yuv422( uint8_t *image, uint16_t **map, int width, int hei */ static inline -void composite_line_yuv( uint8_t *dest, uint8_t *src, int width_src, uint8_t *alpha, int weight, uint16_t *luma, int softness ) +void composite_line_yuv( uint8_t *dest, uint8_t *src, int width_src, uint8_t *alpha, uint8_t *full_alpha, int weight, uint16_t *luma, int softness ) { register int j; int a, mix; @@ -395,13 +395,15 @@ void composite_line_yuv( uint8_t *dest, uint8_t *src, int width_src, uint8_t *al dest++; *dest = ( *src++ * mix + *dest * ( ( 1 << 16 ) - mix ) ) >> 16; dest++; + if ( full_alpha && *full_alpha == 0 ) { *full_alpha = a; } + full_alpha ++; } } /** Composite function. */ -static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint8_t *p_src, int width_src, int height_src, uint8_t *p_alpha, struct geometry_s geometry, int field, uint16_t *p_luma, int32_t softness, composite_line_fn line_fn ) +static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint8_t *p_src, int width_src, int height_src, uint8_t *p_alpha, uint8_t *full_alpha, struct geometry_s geometry, int field, uint16_t *p_luma, int32_t softness, composite_line_fn line_fn ) { int ret = 0; int i; @@ -458,6 +460,9 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint if ( p_alpha ) p_alpha += x_src + y_src * stride_src / bpp; + if ( full_alpha ) + full_alpha += x + y * stride_dest / bpp; + // offset pointer into luma channel based upon cropping if ( p_luma ) p_luma += x_src + y_src * stride_src / bpp; @@ -480,12 +485,15 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint p_src += stride_src; if ( p_alpha ) p_alpha += stride_src / bpp; + if ( full_alpha ) + full_alpha += stride_dest / bpp; height_src--; } stride_src *= step; stride_dest *= step; int alpha_stride = stride_src / bpp; + int full_alpha_stride = stride_dest / bpp; // Make sure than x and w are even if ( x_uneven ) @@ -499,12 +507,14 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint { for ( i = 0; i < height_src; i += step ) { - line_fn( p_dest, p_src, width_src, p_alpha, weight, p_luma, softness ); + line_fn( p_dest, p_src, width_src, p_alpha, full_alpha, weight, p_luma, softness ); p_src += stride_src; p_dest += stride_dest; if ( p_alpha ) p_alpha += alpha_stride; + if ( full_alpha ) + full_alpha += full_alpha_stride; if ( p_luma ) p_luma += alpha_stride; } @@ -513,12 +523,14 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint { for ( i = 0; i < height_src; i += step ) { - composite_line_yuv( p_dest, p_src, width_src, p_alpha, weight, p_luma, softness ); + composite_line_yuv( p_dest, p_src, width_src, p_alpha, full_alpha, weight, p_luma, softness ); p_src += stride_src; p_dest += stride_dest; if ( p_alpha ) p_alpha += alpha_stride; + if ( full_alpha ) + full_alpha += full_alpha_stride; if ( p_luma ) p_luma += alpha_stride; } @@ -1029,6 +1041,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f uint8_t *dest = *image; uint8_t *src = image_b; uint8_t *alpha = mlt_frame_get_alpha_mask( b_frame ); + uint8_t *full_alpha = mlt_frame_get_alpha_mask( a_frame ); int progressive = mlt_properties_get_int( a_props, "consumer_deinterlace" ) || mlt_properties_get_int( properties, "progressive" ); @@ -1039,6 +1052,14 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f //composite_line_fn line_fn = mlt_properties_get_int( properties, "_MMX" ) ? composite_line_yuv_mmx : NULL; composite_line_fn line_fn = NULL; + if ( full_alpha == NULL ) + { + full_alpha = mlt_pool_alloc( *width * *height ); + memset( full_alpha, 255, *width * *height ); + a_frame->get_alpha_mask = NULL; + mlt_properties_set_data( a_props, "alpha", full_alpha, 0, mlt_pool_release, NULL ); + } + for ( field = 0; field < ( progressive ? 1 : 2 ); field++ ) { // Assume lower field (0) first @@ -1061,7 +1082,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f alignment_calculate( &result ); // Composite the b_frame on the a_frame - composite_yuv( dest, *width, *height, src, width_b, height_b, alpha, result, progressive ? -1 : field, luma_bitmap, luma_softness, line_fn ); + composite_yuv( dest, *width, *height, src, width_b, height_b, alpha, full_alpha, result, progressive ? -1 : field, luma_bitmap, luma_softness, line_fn ); } } } @@ -1098,7 +1119,7 @@ static mlt_frame composite_process( mlt_transition this, mlt_frame a_frame, mlt_ mlt_properties props = mlt_properties_get_data( MLT_FRAME_PROPERTIES( b_frame ), "_producer", NULL ); mlt_frame_push_service_int( a_frame, mlt_properties_get_int( props, "in" ) ); mlt_frame_push_service_int( a_frame, mlt_properties_get_int( props, "out" ) ); - mlt_properties_set_int( MLT_FRAME_PROPERTIES( b_frame ), "relative_position", mlt_properties_get_int( props, "_frame" ) ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( b_frame ), "relative_position", mlt_properties_get_int( props, "_frame" ) - mlt_properties_get_int( props, "in" ) ); // Assign the current position to the name mlt_properties_set_position( MLT_FRAME_PROPERTIES( a_frame ), name, mlt_properties_get_position( MLT_FRAME_PROPERTIES( b_frame ), "relative_position" ) ); diff --git a/src/modules/feeds/PAL/etv.properties b/src/modules/feeds/PAL/etv.properties index 85edcbe2..e6993989 100644 --- a/src/modules/feeds/PAL/etv.properties +++ b/src/modules/feeds/PAL/etv.properties @@ -24,7 +24,7 @@ location=region .composite.luma=%luma01.pgm .composite.softness=.3 .filter[0]=watermark -.filter[0].resource=colour:0x6c010100 +.filter[0].resource=colour:0x6c0101ff .filter[1]=watermark .filter[1].resource=pango: .filter[1].producer.text= @@ -46,7 +46,7 @@ courtesy=region .composite.luma=%luma01.pgm .composite.softness=.3 .filter[0]=watermark -.filter[0].resource=colour:0x6c010100 +.filter[0].resource=colour:0x6c0101ff .filter[1]=watermark .filter[1].resource=pango: .filter[1].producer.text= @@ -66,7 +66,7 @@ exclusive=region .properties.length[0]=composite.out .composite.geometry=-230,115:230x30;12=0 .filter[0]=watermark -.filter[0].resource=colour:0x6c010100 +.filter[0].resource=colour:0x6c0101ff .filter[1]=watermark .filter[1].resource=pango: .filter[1].producer.text=ETV Exclusive @@ -86,7 +86,7 @@ file_shot=region .properties.length[0]=composite.out .composite.geometry=590,160:80x25:0;12=,:x:100 .filter[0]=watermark -.filter[0].resource=colour:0x6c010100 +.filter[0].resource=colour:0x6c0101ff .filter[1]=watermark .filter[1].resource=pango: .filter[1].producer.text=File Shot @@ -106,7 +106,7 @@ special=region .properties.length[1]=filter[1].composite.out .composite.geometry=465,375:255x35 .filter[0]=watermark -.filter[0].resource=colour:0x6c010101 +.filter[0].resource=colour:0x6c0101ff .filter[0].composite.geometry=100%,0%:100%x100%:0;12=0%,0%:x:100 .filter[1]=watermark .filter[1].resource=pango: @@ -127,7 +127,7 @@ ticker=region .properties.length[0]=filter[1].composite.out .composite.geometry=0,500:722x75 .filter[0]=watermark -.filter[0].resource=colour:0x6c010100 +.filter[0].resource=colour:0x6c0101ff .filter[0].composite.titles=1 .filter[1]=watermark .filter[1].resource=pango: diff --git a/src/modules/gtk2/producer_pango.c b/src/modules/gtk2/producer_pango.c index b6f733cb..37b1abb2 100644 --- a/src/modules/gtk2/producer_pango.c +++ b/src/modules/gtk2/producer_pango.c @@ -88,6 +88,8 @@ static int alignment_parse( char* align ) return ret; } +static PangoFT2FontMap *fontmap = NULL; + mlt_producer producer_pango_init( const char *filename ) { producer_pango this = calloc( sizeof( struct producer_pango_s ), 1 ); @@ -95,6 +97,10 @@ mlt_producer producer_pango_init( const char *filename ) { mlt_producer producer = &this->parent; + // THIS SHOULD BE MUTEXED... + if ( fontmap == NULL ) + fontmap = (PangoFT2FontMap*) pango_ft2_font_map_new(); + producer->get_frame = producer_get_frame; producer->close = ( mlt_destructor )producer_close; @@ -538,13 +544,8 @@ static void pango_draw_background( GdkPixbuf *pixbuf, rgba_color bg ) } } -static PangoFT2FontMap *fontmap = NULL; - static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const char *font, rgba_color fg, rgba_color bg, int pad, int align, int weight, int size ) { - if ( fontmap == NULL ) - fontmap = (PangoFT2FontMap*) pango_ft2_font_map_new(); - PangoContext *context = pango_ft2_font_map_create_context( fontmap ); PangoLayout *layout = pango_layout_new( context ); int w, h, x; diff --git a/src/modules/plus/filter_affine.c b/src/modules/plus/filter_affine.c index 465e4129..e465a351 100644 --- a/src/modules/plus/filter_affine.c +++ b/src/modules/plus/filter_affine.c @@ -80,6 +80,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * mlt_frame_get_image( a_frame, image, format, width, height, writable ); mlt_properties_set_data( frame_properties, "affine_frame", a_frame, 0, (mlt_destructor)mlt_frame_close, NULL ); mlt_properties_set_data( frame_properties, "image", *image, *width * *height * 2, NULL, NULL ); + mlt_properties_set_data( frame_properties, "alpha", mlt_frame_get_alpha_mask( a_frame ), *width * *height, NULL, NULL ); } } diff --git a/src/modules/plus/transition_affine.c b/src/modules/plus/transition_affine.c index 896fe084..4a8fe091 100644 --- a/src/modules/plus/transition_affine.c +++ b/src/modules/plus/transition_affine.c @@ -518,6 +518,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f start = transition_parse_keys( this, normalised_width, normalised_height ); } + if ( *height & 1 ) + *height ++; + // Fetch the a frame image mlt_frame_get_image( a_frame, image, format, width, height, 1 ); @@ -568,6 +571,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f float fix_shear_x = mlt_properties_get_double( properties, "fix_shear_x" ); float fix_shear_y = mlt_properties_get_double( properties, "fix_shear_y" ); float fix_shear_z = mlt_properties_get_double( properties, "fix_shear_z" ); + float scale_x = mlt_properties_get_double( properties, "scale_x" ); + float scale_y = mlt_properties_get_double( properties, "scale_y" ); float shear_x = mlt_properties_get_double( properties, "shear_x" ); float shear_y = mlt_properties_get_double( properties, "shear_y" ); float shear_z = mlt_properties_get_double( properties, "shear_z" ); @@ -592,7 +597,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f int y_offset = ( int )result.h >> 1; uint8_t *alpha = mlt_frame_get_alpha_mask( b_frame ); - uint8_t *mask = mlt_pool_alloc( b_width * b_height ); + uint8_t *mask = mlt_frame_get_alpha_mask( a_frame ); uint8_t *pmask = mask; float mix; @@ -614,8 +619,12 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f dz = MapZ( affine.matrix, 0, 0 ); - if ( mask != NULL ) - memset( mask, 0, b_width * b_height ); + if ( mask == NULL ) + { + mask = mlt_pool_alloc( *width * *height ); + pmask = mask; + memset( mask, 255, *width * *height ); + } if ( ( int )abs( dz * 1000 ) < 25 ) goto getout; @@ -623,7 +632,11 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f if ( scale ) { affine_max_output( affine.matrix, &sw, &sh, dz ); - affine_scale( affine.matrix, sw, sh ); + affine_scale( affine.matrix, 1.0 / sw, 1.0 / sh ); + } + else if ( scale_x != 0 && scale_y != 0 ) + { + affine_scale( affine.matrix, scale_x, scale_y ); } for ( y = lower_y; y < upper_y; y ++ ) @@ -639,7 +652,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f { if ( alpha == NULL ) { - *pmask ++ = 255; + *pmask ++; dx += dx & 1; *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) ); *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 ); @@ -666,8 +679,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f } getout: - b_frame->get_alpha_mask = NULL; - mlt_properties_set_data( b_props, "alpha", mask, 0, mlt_pool_release, NULL ); + a_frame->get_alpha_mask = NULL; + mlt_properties_set_data( a_props, "alpha", mask, 0, mlt_pool_release, NULL ); } return 0; diff --git a/src/modules/sdl/consumer_sdl_preview.c b/src/modules/sdl/consumer_sdl_preview.c index db2cc402..1d849437 100644 --- a/src/modules/sdl/consumer_sdl_preview.c +++ b/src/modules/sdl/consumer_sdl_preview.c @@ -263,9 +263,6 @@ static void *consumer_thread( void *arg ) // Get the speed of the frame double speed = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ); - // Determine which speed to use - double use_speed = speed; - // Lock during the operation mlt_service_lock( MLT_CONSUMER_SERVICE( consumer ) ); @@ -311,13 +308,13 @@ static void *consumer_thread( void *arg ) mlt_consumer_put_frame( this->active, frame ); } // If we aren't playing normally, then use the still - else if ( use_speed != 1 ) + else if ( speed != 1 ) { if ( !mlt_consumer_is_stopped( this->play ) ) mlt_consumer_stop( this->play ); if ( mlt_consumer_is_stopped( this->still ) ) { - this->last_speed = use_speed; + this->last_speed = speed; this->active = this->still; this->ignore_change = 0; mlt_consumer_start( this->still ); @@ -331,7 +328,7 @@ static void *consumer_thread( void *arg ) mlt_consumer_stop( this->still ); if ( mlt_consumer_is_stopped( this->play ) ) { - this->last_speed = use_speed; + this->last_speed = speed; this->active = this->play; this->ignore_change = 25; mlt_consumer_start( this->play ); diff --git a/src/modules/westley/consumer_westley.c b/src/modules/westley/consumer_westley.c index 51f33059..253b7ca1 100644 --- a/src/modules/westley/consumer_westley.c +++ b/src/modules/westley/consumer_westley.c @@ -549,7 +549,7 @@ static void serialise_service( serialise_context context, mlt_service service, x if ( strcmp( mlt_type, "producer" ) == 0 ) { char *mlt_service = mlt_properties_get( properties, "mlt_service" ); - if ( mlt_properties_get( properties, "westley" ) == NULL && !strcmp( mlt_service, "tractor" ) ) + if ( mlt_properties_get( properties, "westley" ) == NULL && ( mlt_service != NULL && !strcmp( mlt_service, "tractor" ) ) ) { context->pass = 0; serialise_tractor( context, service, node ); diff --git a/src/modules/westley/producer_westley.c b/src/modules/westley/producer_westley.c index f929ca56..c550ae46 100644 --- a/src/modules/westley/producer_westley.c +++ b/src/modules/westley/producer_westley.c @@ -296,6 +296,8 @@ static void on_start_tractor( deserialise_context context, const xmlChar *name, for ( ; atts != NULL && *atts != NULL; atts += 2 ) mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), (char*) atts[0], atts[1] == NULL ? "" : (char*) atts[1] ); + mlt_properties_set_int( MLT_TRACTOR_PROPERTIES( tractor ), "global_feed", 1 ); + if ( mlt_properties_get( properties, "id" ) != NULL ) mlt_properties_set_data( context->producer_map, mlt_properties_get( properties, "id" ), service, 0, NULL, NULL ); -- 2.39.2