Minor corrections with alpha and affines
[melted] / src / modules / plus / transition_affine.c
index 42c03a2..636773a 100644 (file)
@@ -497,11 +497,16 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        mlt_position position =  mlt_properties_get_position( a_props, name );
        mlt_position in = mlt_properties_get_position( properties, "in" );
        mlt_position out = mlt_properties_get_position( properties, "out" );
+       int mirror = mlt_properties_get_position( properties, "mirror" );
+       int length = out - in + 1;
 
        // Structures for geometry
        struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
        struct geometry_s result;
 
+       if ( mirror && position > length / 2 )
+               position = abs( position - length );
+
        // Now parse the geometries
        if ( start == NULL )
        {
@@ -517,7 +522,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 ) / ( out - in + 1 ) );
+       composite_calculate( &result, this, a_frame, ( float )position / length );
 
        // Fetch the b frame image
        result.w = ( int )( result.w * *width / result.nw );
@@ -563,6 +568,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                float fix_shear_x = mlt_properties_get_double( properties, "fix_shear_x" );
                float fix_shear_y = mlt_properties_get_double( properties, "fix_shear_y" );
                float fix_shear_z = mlt_properties_get_double( properties, "fix_shear_z" );
+               float scale_x = mlt_properties_get_double( properties, "scale_x" );
+               float scale_y = mlt_properties_get_double( properties, "scale_y" );
                float shear_x = mlt_properties_get_double( properties, "shear_x" );
                float shear_y = mlt_properties_get_double( properties, "shear_y" );
                float shear_z = mlt_properties_get_double( properties, "shear_z" );
@@ -587,19 +594,19 @@ 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 *mask = mlt_frame_get_alpha_mask( a_frame );
                uint8_t *pmask = mask;
                float mix;
 
                affine_t affine;
                affine_init( affine.matrix );
-               affine_rotate( affine.matrix, fix_rotate_x + rotate_x * ( position - in ) );
-               affine_rotate_y( affine.matrix, fix_rotate_y + rotate_y * ( position - in ) );
-               affine_rotate_z( affine.matrix, fix_rotate_z + rotate_z * ( position - in ) );
+               affine_rotate( affine.matrix, fix_rotate_x + rotate_x * position );
+               affine_rotate_y( affine.matrix, fix_rotate_y + rotate_y * position );
+               affine_rotate_z( affine.matrix, fix_rotate_z + rotate_z * position );
                affine_shear( affine.matrix, 
-                                         fix_shear_x + shear_x * ( position - in ), 
-                                         fix_shear_y + shear_y * ( position - in ),
-                                         fix_shear_z + shear_z * ( position - in ) );
+                                         fix_shear_x + shear_x * position, 
+                                         fix_shear_y + shear_y * position,
+                                         fix_shear_z + shear_z * position );
                affine_offset( affine.matrix, ox, oy );
 
                lower_x -= ( lower_x & 1 );
@@ -609,8 +616,12 @@ 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 );
+               if ( mask == NULL )
+               {
+                       mask = mlt_pool_alloc( *width * *height );
+                       pmask = mask;
+                       memset( mask, 255, *width * *height );
+               }
 
                if ( ( int )abs( dz * 1000 ) < 25 )
                        goto getout;
@@ -620,6 +631,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        affine_max_output( affine.matrix, &sw, &sh, dz );
                        affine_scale( affine.matrix, sw, sh );
                }
+               else if ( scale_x != 0 && scale_y != 0 )
+               {
+                       affine_scale( affine.matrix, scale_x, scale_y );
+               }
 
                for ( y = lower_y; y < upper_y; y ++ )
                {
@@ -634,7 +649,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                {
                                        if ( alpha == NULL )
                                        {
-                                               *pmask ++ = 255;
+                                               *pmask ++;
                                                dx += dx & 1;
                                                *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) );
                                                *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 );
@@ -661,8 +676,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                }
 
 getout:
-               b_frame->get_alpha_mask = NULL;
-               mlt_properties_set_data( b_props, "alpha", mask, 0, mlt_pool_release, NULL );
+               a_frame->get_alpha_mask = NULL;
+               mlt_properties_set_data( a_props, "alpha", mask, 0, mlt_pool_release, NULL );
        }
 
        return 0;