+ Yet another aspect ratio correction for the filter transition (not 100% correct...
[melted] / src / modules / core / transition_composite.c
index 21909e8..4cbf324 100644 (file)
@@ -732,12 +732,11 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
                int normalised_height = geometry->item.h;
                int real_width = get_value( b_props, "real_width", "width" );
                int real_height = get_value( b_props, "real_height", "height" );
-               double input_ar = mlt_frame_get_aspect_ratio( b_frame );
+               double input_ar = mlt_properties_get_double( b_props, "aspect_ratio" );
                double output_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" );
-               if ( input_ar == 0.0 ) input_ar = output_ar;
-               int scaled_width = input_ar / output_ar * real_width;
+               int scaled_width = ( input_ar == 0.0 ? output_ar : input_ar ) / output_ar * real_width;
                int scaled_height = real_height;
-                       
+
                // Now ensure that our images fit in the normalised frame
                if ( scaled_width > normalised_width )
                {
@@ -752,7 +751,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
 
                // Honour the fill request - this will scale the image to fill width or height while maintaining a/r
                // ????: Shouln't this be the default behaviour?
-               if ( mlt_properties_get_int( properties, "fill" ) )
+               if ( mlt_properties_get_int( properties, "fill" ) && scaled_width > 0 && scaled_height > 0 )
                {
                        if ( scaled_height < normalised_height && scaled_width * normalised_height / scaled_height < normalised_width )
                        {
@@ -1012,6 +1011,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                int width_b = *width;
                int height_b = *height;
        
+               // Vars for alphas
+               uint8_t *alpha_a = NULL;
+               uint8_t *alpha_b = NULL;
+
                // Composites always need scaling... defaulting to lowest
                char *rescale = mlt_properties_get( a_props, "rescale.interp" );
                if ( rescale == NULL || !strcmp( rescale, "none" ) )
@@ -1025,9 +1028,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                // Since we are the consumer of the b_frame, we must pass along these
                // consumer properties from the a_frame
                mlt_properties_set_double( b_props, "consumer_deinterlace", mlt_properties_get_double( a_props, "consumer_deinterlace" ) );
+               mlt_properties_set( b_props, "consumer_deinterlace_method", mlt_properties_get( a_props, "consumer_deinterlace_method" ) );
                mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
-               mlt_properties_set_int( b_props, "normalised_width", mlt_properties_get_double( a_props, "normalised_width" ) );
-               mlt_properties_set_int( b_props, "normalised_height", mlt_properties_get_double( a_props, "normalised_height" ) );
 
                // TODO: Dangerous/temporary optimisation - if nothing to do, then do nothing
                if ( mlt_properties_get_int( properties, "no_alpha" ) && 
@@ -1040,10 +1042,16 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                }
 
                if ( a_frame == b_frame )
+               {
+                       double aspect_ratio = mlt_frame_get_aspect_ratio( b_frame );
                        get_b_frame_image( this, b_frame, &image_b, &width_b, &height_b, &result );
+                       alpha_b = mlt_frame_get_alpha_mask( b_frame );
+                       mlt_properties_set_double( a_props, "aspect_ratio", aspect_ratio );
+               }
 
                // Get the image from the a frame
                mlt_frame_get_image( a_frame, image, format, width, height, 1 );
+               alpha_a = mlt_frame_get_alpha_mask( a_frame );
 
                // Optimisation - no compositing required
                if ( result.item.mix == 0 || ( result.item.w == 0 && result.item.h == 0 ) )
@@ -1072,12 +1080,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        height_b = mlt_properties_get_int( a_props, "dest_height" );
                }
 
-               if ( image_b != NULL || get_b_frame_image( this, b_frame, &image_b, &width_b, &height_b, &result ) == 0 )
+               if ( *image != image_b && ( image_b != NULL || get_b_frame_image( this, b_frame, &image_b, &width_b, &height_b, &result ) == 0 ) )
                {
                        uint8_t *dest = *image;
                        uint8_t *src = image_b;
-                       uint8_t *alpha_b = mlt_frame_get_alpha_mask( b_frame );
-                       uint8_t *alpha_a = mlt_frame_get_alpha_mask( a_frame );
                        int progressive = 
                                        mlt_properties_get_int( a_props, "consumer_deinterlace" ) ||
                                        mlt_properties_get_int( properties, "progressive" );
@@ -1085,8 +1091,13 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        
                        int32_t luma_softness = mlt_properties_get_double( properties, "softness" ) * ( 1 << 16 );
                        uint16_t *luma_bitmap = get_luma( properties, width_b, height_b );
+                       char *operator = mlt_properties_get( properties, "operator" );
+
+                       alpha_b = alpha_b == NULL ? mlt_frame_get_alpha_mask( b_frame ) : alpha_b;
+
                        composite_line_fn line_fn = composite_line_yuv;
 
+                       // Silly - this isn't a good solution - deprecating
                        if ( mlt_properties_get_int( properties, "or" ) )
                                line_fn = composite_line_yuv_or;
                        if ( mlt_properties_get_int( properties, "and" ) )
@@ -1094,6 +1105,18 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        if ( mlt_properties_get_int( properties, "xor" ) )
                                line_fn = composite_line_yuv_xor;
 
+                       // Replacement and override
+                       if ( operator != NULL )
+                       {
+                               if ( !strcmp( operator, "or" ) )
+                                       line_fn = composite_line_yuv_or;
+                               if ( !strcmp( operator, "and" ) )
+                                       line_fn = composite_line_yuv_and;
+                               if ( !strcmp( operator, "xor" ) )
+                                       line_fn = composite_line_yuv_xor;
+                       }
+
+                       // Allow the user to completely obliterate the alpha channels from both frames
                        if ( mlt_properties_get( properties, "alpha_a" ) )
                                memset( alpha_a, mlt_properties_get_int( properties, "alpha_a" ), *width * *height );