Skip to content

Commit

Permalink
+ Added an option to override alignment and transparent borders for c…
Browse files Browse the repository at this point in the history
…ompositing

git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@849 d19143bc-622f-0410-bfdd-b5b2a6649095
  • Loading branch information
lilo_booter committed Oct 10, 2005
1 parent 490c886 commit 7651a18
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/framework/mlt_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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 );

Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/framework/mlt_tractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/modules/core/filter_luma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
16 changes: 14 additions & 2 deletions src/modules/core/transition_composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) )
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 );
}
Expand Down
8 changes: 7 additions & 1 deletion src/modules/core/transition_luma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down

0 comments on commit 7651a18

Please sign in to comment.