From 7651a182bf7191ab5db9b3741caeac2f86540281 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Mon, 10 Oct 2005 09:28:12 +0000 Subject: [PATCH] + Added an option to override alignment and transparent borders for compositing git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@849 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_frame.c | 8 +++++--- src/framework/mlt_tractor.c | 1 + src/modules/core/filter_luma.c | 2 +- src/modules/core/transition_composite.c | 16 ++++++++++++++-- src/modules/core/transition_luma.c | 8 +++++++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 2ee3569d..115978dd 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -638,7 +638,7 @@ int mlt_convert_yuv420p_to_yuv422( uint8_t *yuv420p, int width, int height, int return ret; } -uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight ) +uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight, uint8_t alpha_value ) { uint8_t *output = NULL; @@ -650,7 +650,7 @@ uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iused = iwidth; output = mlt_pool_alloc( owidth * oheight ); - memset( output, 0, owidth * oheight ); + memset( output, alpha_value, owidth * oheight ); offset_x -= offset_x % 2; @@ -741,6 +741,8 @@ uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight ) // If width and height are correct, don't do anything if ( iwidth != owidth || iheight != oheight ) { + uint8_t alpha_value = mlt_properties_get_int( properties, "resize_alpha" ); + // Create the output image uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 ); @@ -753,7 +755,7 @@ uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight ) mlt_properties_set_int( properties, "height", oheight ); // We should resize the alpha too - alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight ); + alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight, alpha_value ); if ( alpha != NULL ) { mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL ); diff --git a/src/framework/mlt_tractor.c b/src/framework/mlt_tractor.c index 094352e3..fae6c2e1 100644 --- a/src/framework/mlt_tractor.c +++ b/src/framework/mlt_tractor.c @@ -205,6 +205,7 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma mlt_frame frame = mlt_frame_pop_service( this ); mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame ); mlt_properties_set( frame_properties, "rescale.interp", mlt_properties_get( properties, "rescale.interp" ) ); + mlt_properties_set_int( frame_properties, "rescale_alpha", mlt_properties_get_int( properties, "resize_alpha" ) ); mlt_properties_set_int( frame_properties, "distort", mlt_properties_get_int( properties, "distort" ) ); mlt_properties_set_double( frame_properties, "consumer_aspect_ratio", mlt_properties_get_double( properties, "consumer_aspect_ratio" ) ); mlt_properties_set_int( frame_properties, "consumer_deinterlace", mlt_properties_get_int( properties, "consumer_deinterlace" ) ); diff --git a/src/modules/core/filter_luma.c b/src/modules/core/filter_luma.c index 878fb6a4..94f06c7d 100644 --- a/src/modules/core/filter_luma.c +++ b/src/modules/core/filter_luma.c @@ -58,7 +58,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * } } - if ( b_frame == NULL ) + if ( b_frame == NULL || mlt_properties_get_int( b_frame, "width" ) != *width || mlt_properties_get_int( b_frame, "height" ) != *height ) { b_frame = mlt_frame_init( ); mlt_properties_set_data( properties, "frame", b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); diff --git a/src/modules/core/transition_composite.c b/src/modules/core/transition_composite.c index b28283d8..2bc48210 100644 --- a/src/modules/core/transition_composite.c +++ b/src/modules/core/transition_composite.c @@ -715,8 +715,9 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** // Get the properties objects mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame ); mlt_properties properties = MLT_TRANSITION_PROPERTIES( this ); + uint8_t resize_alpha = mlt_properties_get_int( b_props, "resize_alpha" ); - if ( mlt_properties_get_int( properties, "distort" ) == 0 && mlt_properties_get_int( b_props, "distort" ) == 0 && geometry->item.distort == 0 ) + if ( mlt_properties_get_int( properties, "aligned" ) && mlt_properties_get_int( properties, "distort" ) == 0 && mlt_properties_get_int( b_props, "distort" ) == 0 && geometry->item.distort == 0 ) { // Adjust b_frame pixel aspect int normalised_width = geometry->item.w; @@ -769,7 +770,12 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** } // We want to ensure that we bypass resize now... - mlt_properties_set_int( b_props, "distort", mlt_properties_get_int( properties, "distort" ) ); + if ( resize_alpha == 0 ) + mlt_properties_set_int( b_props, "distort", mlt_properties_get_int( properties, "distort" ) ); + + // If we're not aligned, we want a non-transparent background + if ( mlt_properties_get_int( properties, "aligned" ) == 0 ) + mlt_properties_set_int( b_props, "resize_alpha", 255 ); // Take into consideration alignment for optimisation (titles are a special case) if ( !mlt_properties_get_int( properties, "titles" ) ) @@ -781,6 +787,9 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** ret = mlt_frame_get_image( b_frame, image, &format, width, height, 1 ); + // Set the frame back + mlt_properties_set_int( b_props, "resize_alpha", resize_alpha ); + return ret && image != NULL; } @@ -1196,6 +1205,9 @@ mlt_transition transition_composite_init( char *arg ) // Default factory mlt_properties_set( properties, "factory", "fezzik" ); + // Use alignment (and hence alpha of b frame) + mlt_properties_set_int( properties, "aligned", 1 ); + // Inform apps and framework that this is a video only transition mlt_properties_set_int( properties, "_transition_type", 1 ); } diff --git a/src/modules/core/transition_luma.c b/src/modules/core/transition_luma.c index 29eb0958..e55046cf 100644 --- a/src/modules/core/transition_luma.c +++ b/src/modules/core/transition_luma.c @@ -69,8 +69,10 @@ static inline int dissolve_yuv( mlt_frame this, mlt_frame that, float weight, in int width_src = width, height_src = height; mlt_image_format format = mlt_image_yuv422; uint8_t *p_src, *p_dest; - uint8_t *p; + uint8_t *p, *q; uint8_t *limit; + uint8_t *alpha_src; + uint8_t *alpha_dst; int32_t weigh = weight * ( 1 << 16 ); int32_t weigh_complement = ( 1 - weight ) * ( 1 << 16 ); @@ -79,19 +81,23 @@ static inline int dissolve_yuv( mlt_frame this, mlt_frame that, float weight, in mlt_properties_set( &that->parent, "distort", mlt_properties_get( &this->parent, "distort" ) ); mlt_properties_set_int( &that->parent, "consumer_deinterlace", mlt_properties_get_int( &this->parent, "consumer_deinterlace" ) ); mlt_frame_get_image( this, &p_dest, &format, &width, &height, 1 ); + alpha_dst = mlt_frame_get_alpha_mask( this ); mlt_frame_get_image( that, &p_src, &format, &width_src, &height_src, 0 ); + alpha_src = mlt_frame_get_alpha_mask( that ); // Pick the lesser of two evils ;-) width_src = width_src > width ? width : width_src; height_src = height_src > height ? height : height_src; p = p_dest; + q = alpha_dst; limit = p_dest + height_src * width_src * 2; while ( p < limit ) { *p_dest++ = ( *p_src++ * weigh + *p++ * weigh_complement ) >> 16; *p_dest++ = ( *p_src++ * weigh + *p++ * weigh_complement ) >> 16; + *alpha_dst++ = ( *alpha_src++ * weigh + *q++ * weigh_complement ) >> 16; } return ret; -- 2.39.2