]> git.sesse.net Git - mlt/blobdiff - src/modules/core/transition_composite.c
Factor out some frame properties in transitions.
[mlt] / src / modules / core / transition_composite.c
index 2e29ac809f50f08a1938548b7e22fb83544608d0..7b2622b3e50aa63e894dc7595b4715c3a8339358 100644 (file)
@@ -98,10 +98,8 @@ static mlt_geometry transition_parse_keys( mlt_transition this, int normalised_w
        // Create an empty geometries object
        mlt_geometry geometry = mlt_geometry_init( );
 
-       // Get the in and out position
-       mlt_position in = mlt_transition_get_in( this );
-       mlt_position out = mlt_transition_get_out( this );
-       int length = out - in + 1;
+       // Get the duration
+       mlt_position length = mlt_transition_get_length( this );
        double cycle = mlt_properties_get_double( properties, "cycle" );
 
        // Get the new style geometry string
@@ -187,20 +185,6 @@ static int position_calculate( mlt_transition this, mlt_position position )
 /** Calculate the field delta for this frame - position between two frames.
 */
 
-static inline double delta_calculate( mlt_transition this, mlt_frame frame, mlt_position position )
-{
-       // Get the in and out position
-       mlt_position in = mlt_transition_get_in( this );
-       mlt_position out = mlt_transition_get_out( this );
-       double length = out - in + 1;
-
-       // Now do the calcs
-       double x = ( double )( position - in ) / length;
-       double y = ( double )( position + 1 - in ) / length;
-
-       return length * ( y - x ) / 2.0;
-}
-
 static int get_value( mlt_properties properties, const char *preferred, const char *fallback )
 {
        int value = mlt_properties_get_int( properties, preferred );
@@ -766,6 +750,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
        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" );
+       double consumer_ar = mlt_profile_sar( mlt_service_profile( MLT_TRANSITION_SERVICE(this) ) );
 
        // Do not scale if we are cropping - the compositing rectangle can crop the b image
        // TODO: Use the animatable w and h of the crop geometry to scale independently of crop rectangle
@@ -774,7 +759,6 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
                int real_width = get_value( b_props, "real_width", "width" );
                int real_height = get_value( b_props, "real_height", "height" );
                double input_ar = mlt_properties_get_double( b_props, "aspect_ratio" );
-               double consumer_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" );
                double background_ar = mlt_properties_get_double( b_props, "output_ratio" );
                double output_ar = background_ar != 0.0 ? background_ar : consumer_ar;
                int scaled_width = rint( ( input_ar == 0.0 ? output_ar : input_ar ) / output_ar * real_width );
@@ -791,7 +775,6 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
                int real_width = get_value( b_props, "real_width", "width" );
                int real_height = get_value( b_props, "real_height", "height" );
                double input_ar = mlt_properties_get_double( b_props, "aspect_ratio" );
-               double consumer_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" );
                double background_ar = mlt_properties_get_double( b_props, "output_ratio" );
                double output_ar = background_ar != 0.0 ? background_ar : consumer_ar;
                int scaled_width = rint( ( input_ar == 0.0 ? output_ar : input_ar ) / output_ar * real_width );
@@ -853,6 +836,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
 
        // Adjust to consumer scale
        *width = rint( geometry->sw * *width / geometry->nw );
+       *width -= *width % 2; // coerce to even width for yuv422
        *height = rint( geometry->sh * *height / geometry->nh );
 // fprintf(stderr, "%s: scaled %dx%d norm %dx%d resize %dx%d\n", __FILE__,
 // geometry->sw, geometry->sh, geometry->nw, geometry->nh, *width, *height);
@@ -881,9 +865,7 @@ static void crop_calculate( mlt_transition this, mlt_properties properties, stru
                if ( !crop )
                {
                        crop = mlt_geometry_init();
-                       mlt_position in = mlt_transition_get_in( this );
-                       mlt_position out = mlt_transition_get_out( this );
-                       int length = out - in + 1;
+                       mlt_position length = mlt_transition_get_length( this );
                        double cycle = mlt_properties_get_double( properties, "cycle" );
 
                        // Allow a geometry repeat cycle
@@ -951,7 +933,7 @@ static mlt_geometry composite_calculate( mlt_transition this, struct geometry_s
                }
                else
                {
-                       int length = mlt_transition_get_out( this ) - mlt_transition_get_in( this ) + 1;
+                       mlt_position length = mlt_transition_get_length( this );
                        double cycle = mlt_properties_get_double( properties, "cycle" );
                        if ( cycle > 1 )
                                length = cycle;
@@ -999,10 +981,14 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_pos
        uint8_t *dest = NULL;
 
        // Get the image and dimensions
-       uint8_t *image = mlt_properties_get_data( a_props, "image", NULL );
+       uint8_t *image = NULL;
        int width = mlt_properties_get_int( a_props, "width" );
        int height = mlt_properties_get_int( a_props, "height" );
-       int format = mlt_properties_get_int( a_props, "format" );
+       mlt_image_format format = mlt_image_yuv422;
+
+       mlt_frame_get_image( a_frame, &image, &format, &width, &height, 0 );
+       if ( !image )
+               return b_frame;
 
        // Pointers for copy operation
        uint8_t *p;
@@ -1047,7 +1033,7 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_pos
        dest = mlt_pool_alloc( w * h * 2 );
 
        // Assign to the new frame
-       mlt_properties_set_data( b_props, "image", dest, w * h * 2, mlt_pool_release, NULL );
+       mlt_frame_set_image( b_frame, dest, w * h * 2, mlt_pool_release );
        mlt_properties_set_int( b_props, "width", w );
        mlt_properties_set_int( b_props, "height", h );
        mlt_properties_set_int( b_props, "format", format );
@@ -1133,24 +1119,17 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                struct geometry_s result;
 
                // Calculate the position
-               double delta = delta_calculate( this, a_frame, position );
+               double delta = mlt_transition_get_progress_delta( this, a_frame );
 
                // Get the image from the b frame
                uint8_t *image_b = NULL;
-               int width_b = *width;
-               int height_b = *height;
+               int width_b = *width > 0 ? *width : mlt_properties_get_int( a_props, "normalised_width" );
+               int height_b = *height > 0 ? *height : mlt_properties_get_int( a_props, "normalised_height" );
        
                // Vars for alphas
                uint8_t *alpha_a = NULL;
                uint8_t *alpha_b = NULL;
 
-               // Composites always need scaling... defaulting to lowest
-               const char *rescale = mlt_properties_get( a_props, "rescale.interp" );
-               if ( rescale == NULL || !strcmp( rescale, "none" ) )
-                       rescale = "nearest";
-               mlt_properties_set( a_props, "rescale.interp", rescale );
-               mlt_properties_set( b_props, "rescale.interp", rescale );
-
                // Do the calculation
                // NB: Locks needed here since the properties are being modified
                int invert = mlt_properties_get_int( properties, "invert" );
@@ -1158,11 +1137,12 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                composite_calculate( this, &result, invert ? b_frame : a_frame, position );
                mlt_service_unlock( MLT_TRANSITION_SERVICE( this ) );
 
-               // Since we are the consumer of the b_frame, we must pass along these
-               // consumer properties from the a_frame
-               mlt_properties_set_int( b_props, "consumer_deinterlace", mlt_properties_get_int( a_props, "consumer_deinterlace" ) || mlt_properties_get_int( properties, "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" ) );
+               // Manual option to deinterlace
+               if ( mlt_properties_get_int( properties, "deinterlace" ) )
+               {
+                       mlt_properties_set_int( a_props, "consumer_deinterlace", 1 );
+                       mlt_properties_set_int( a_props, "consumer_deinterlace", 1 );
+               }
 
                // TODO: Dangerous/temporary optimisation - if nothing to do, then do nothing
                if ( mlt_properties_get_int( properties, "no_alpha" ) && 
@@ -1223,7 +1203,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        int field;
                        
                        double luma_softness = mlt_properties_get_double( properties, "softness" );
+                       mlt_service_lock( MLT_TRANSITION_SERVICE( this ) );
                        uint16_t *luma_bitmap = get_luma( this, properties, width_b, height_b );
+                       mlt_service_unlock( MLT_TRANSITION_SERVICE( this ) );
                        char *operator = mlt_properties_get( properties, "operator" );
 
                        alpha_b = alpha_b == NULL ? mlt_frame_get_alpha_mask( b_frame ) : alpha_b;