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;
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;
// 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 );
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 );
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" ) );
}
}
- 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 );
// 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;
}
// 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" ) )
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;
}
// 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 );
}
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 );
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;