Composite distort, fill and titles rework
[melted] / src / modules / plus / transition_affine.c
index 6154771..806b140 100644 (file)
@@ -177,7 +177,7 @@ static struct geometry_s *transition_parse_keys( mlt_transition this,  int norma
        int i = 0;
 
        // Get the properties of the transition
-       mlt_properties properties = mlt_transition_properties( this );
+       mlt_properties properties = MLT_TRANSITION_PROPERTIES( this );
 
        // Get the in and out position
        mlt_position in = mlt_transition_get_in( this );
@@ -257,10 +257,10 @@ static struct geometry_s *transition_parse_keys( mlt_transition this,  int norma
 struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transition this, mlt_frame a_frame, float position )
 {
        // Get the properties from the transition
-       mlt_properties properties = mlt_transition_properties( this );
+       mlt_properties properties = MLT_TRANSITION_PROPERTIES( this );
 
        // Get the properties from the frame
-       mlt_properties a_props = mlt_frame_properties( a_frame );
+       mlt_properties a_props = MLT_FRAME_PROPERTIES( a_frame );
        
        // Structures for geometry
        struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
@@ -476,13 +476,13 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        mlt_transition this = mlt_frame_pop_service( a_frame );
 
        // Get the properties of the transition
-       mlt_properties properties = mlt_transition_properties( this );
+       mlt_properties properties = MLT_TRANSITION_PROPERTIES( this );
 
        // Get the properties of the a frame
-       mlt_properties a_props = mlt_frame_properties( a_frame );
+       mlt_properties a_props = MLT_FRAME_PROPERTIES( a_frame );
 
        // Get the properties of the b frame
-       mlt_properties b_props = mlt_frame_properties( b_frame );
+       mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
 
        // Image, format, width, height and image for the b frame
        uint8_t *b_image = NULL;
@@ -517,7 +517,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        mlt_frame_get_image( a_frame, image, format, width, height, 1 );
 
        // Calculate the region now
-       composite_calculate( &result, this, a_frame, ( float )( position - in ) / ( out - in + 1 ) );
+       composite_calculate( &result, this, a_frame, ( float )( position ) / ( out - in + 1 ) );
 
        // Fetch the b frame image
        result.w = ( int )( result.w * *width / result.nw );
@@ -540,7 +540,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
        }
 
-       mlt_properties_set( b_props, "distort", mlt_properties_get( properties, "distort" ) );
+       mlt_properties_set_int( b_props, "distort", mlt_properties_get_int( properties, "distort" ) );
        mlt_frame_get_image( b_frame, &b_image, &b_format, &b_width, &b_height, 0 );
        result.w = b_width;
        result.h = b_height;
@@ -587,6 +587,8 @@ 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 *pmask = mask;
                float mix;
 
                affine_t affine;
@@ -613,6 +615,9 @@ 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 );
+
                for ( y = lower_y; y < upper_y; y ++ )
                {
                        p = q;
@@ -626,12 +631,14 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                {
                                        if ( alpha == NULL )
                                        {
+                                               *pmask ++ = 255;
                                                dx += dx & 1;
                                                *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) );
                                                *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 );
                                        }
                                        else
                                        {
+                                               *pmask ++ = *( alpha + dy * b_width + dx );
                                                mix = ( float )*( alpha + dy * b_width + dx ) / 255.0;
                                                dx += dx & 1;
                                                *p = *p * ( 1 - mix ) + mix * *( b_image + dy * b_stride + ( dx << 1 ) );
@@ -643,11 +650,15 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                else
                                {
                                        p += 2;
+                                       pmask ++;
                                }
                        }
 
                        q += a_stride;
                }
+
+               b_frame->get_alpha_mask = NULL;
+               mlt_properties_set_data( b_props, "alpha", mask, 0, mlt_pool_release, NULL );
        }
 
        return 0;
@@ -659,10 +670,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 static mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
 {
        // Get a unique name to store the frame position
-       char *name = mlt_properties_get( mlt_transition_properties( transition ), "_unique_id" );
+       char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
 
        // Assign the current position to the name
-       mlt_properties a_props = mlt_frame_properties( a_frame );
+       mlt_properties a_props = MLT_FRAME_PROPERTIES( a_frame );
        mlt_properties_set_position( a_props, name, mlt_frame_get_position( a_frame ) );
 
        // Push the transition on to the frame
@@ -674,7 +685,6 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram
        // Push the transition method
        mlt_frame_push_get_image( a_frame, transition_get_image );
 
-
        return a_frame;
 }
 
@@ -686,10 +696,10 @@ mlt_transition transition_affine_init( char *arg )
        mlt_transition transition = mlt_transition_new( );
        if ( transition != NULL )
        {
-               mlt_properties_set_int( mlt_transition_properties( transition ), "sx", 1 );
-               mlt_properties_set_int( mlt_transition_properties( transition ), "sy", 1 );
-               mlt_properties_set( mlt_transition_properties( transition ), "distort", NULL );
-               mlt_properties_set( mlt_transition_properties( transition ), "start", "0,0:100%x100%" );
+               mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "sx", 1 );
+               mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "sy", 1 );
+               mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "distort", 0 );
+               mlt_properties_set( MLT_TRANSITION_PROPERTIES( transition ), "start", "0,0:100%x100%" );
                transition->process = transition_process;
        }
        return transition;