]> git.sesse.net Git - mlt/commitdiff
+ Added an option to override alignment and transparent borders for compositing
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 10 Oct 2005 09:28:12 +0000 (09:28 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 10 Oct 2005 09:28:12 +0000 (09:28 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@849 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_frame.c
src/framework/mlt_tractor.c
src/modules/core/filter_luma.c
src/modules/core/transition_composite.c
src/modules/core/transition_luma.c

index 2ee3569da342070254fa3037b5e2bd423f5529c2..115978dd1cc5103c6c4fa69bd8d26c23a1c0eb01 100644 (file)
@@ -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 );
index 094352e32678ccb70ef7959dbabaec3f91dcc304..fae6c2e1a387ed267b9d54cb72dbd1d2c48ed205 100644 (file)
@@ -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" ) );
index 878fb6a4cde0108452c9ae808016313febd3b118..94f06c7dd7e6ffdf3eba3a89bdebd99b07ebf4bb 100644 (file)
@@ -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 );
index b28283d812a8ecd2a16a8b64beacc9598cb8d28c..2bc482100c1e7e3565f38b4510e49920e30f0ba9 100644 (file)
@@ -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 );
        }
index 29eb09582d1de3192150c692a12ca170c7089662..e55046cf26826fb595ef36ba097f437a96a87e53 100644 (file)
@@ -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;