]> git.sesse.net Git - mlt/blobdiff - src/modules/core/transition_composite.c
Mutable watermark producer and small optimisation
[mlt] / src / modules / core / transition_composite.c
index f8f78c96b98b4db68af8733bee27b738006b4d23..622ae8fe85546443763735e77f38a015be600b07 100644 (file)
@@ -275,9 +275,6 @@ static struct geometry_s *transition_parse_keys( mlt_transition this,  int norma
        else
                end->position = 1;
 
-       // Assign to properties to ensure we get destroyed
-       mlt_properties_set_data( properties, "geometries", start, 0, transition_destroy_keys, NULL );
-
        return start;
 }
 
@@ -622,20 +619,34 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        stride_dest *= step;
        int alpha_stride = stride_src / bpp;
 
-       if ( line_fn == NULL )
-               line_fn = composite_line_yuv;
-
        // now do the compositing only to cropped extents
-       for ( i = 0; i < height_src; i += step )
+       if ( line_fn != NULL )
        {
-               line_fn( p_dest, p_src, width_src, p_alpha, weight, p_luma, softness );
-
-               p_src += stride_src;
-               p_dest += stride_dest;
-               if ( p_alpha )
-                       p_alpha += alpha_stride;
-               if ( p_luma )
-                       p_luma += alpha_stride;
+               for ( i = 0; i < height_src; i += step )
+               {
+                       line_fn( p_dest, p_src, width_src, p_alpha, weight, p_luma, softness );
+       
+                       p_src += stride_src;
+                       p_dest += stride_dest;
+                       if ( p_alpha )
+                               p_alpha += alpha_stride;
+                       if ( p_luma )
+                               p_luma += alpha_stride;
+               }
+       }
+       else
+       {
+               for ( i = 0; i < height_src; i += step )
+               {
+                       composite_line_yuv( p_dest, p_src, width_src, p_alpha, weight, p_luma, softness );
+       
+                       p_src += stride_src;
+                       p_dest += stride_dest;
+                       if ( p_alpha )
+                               p_alpha += alpha_stride;
+                       if ( p_luma )
+                               p_luma += alpha_stride;
+               }
        }
 
        return ret;
@@ -849,7 +860,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
 }
 
 
-struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transition this, mlt_frame a_frame, float position )
+static 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 );
@@ -861,7 +872,7 @@ struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transitio
        struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
 
        // Now parse the geometries
-       if ( start == NULL )
+       if ( start == NULL || mlt_properties_get_int( properties, "refresh" ) )
        {
                // Obtain the normalised width and height from the a_frame
                int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
@@ -869,6 +880,10 @@ struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transitio
 
                // Parse the transitions properties
                start = transition_parse_keys( this, normalised_width, normalised_height );
+
+               // Assign to properties to ensure we get destroyed
+               mlt_properties_set_data( properties, "geometries", start, 0, transition_destroy_keys, NULL );
+               mlt_properties_set_int( properties, "refresh", 0 );
        }
 
        // Do the calculation
@@ -881,6 +896,16 @@ struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transitio
        return start;
 }
 
+static inline void inline_memcpy( uint8_t *dest, uint8_t *src, int length )
+{
+       uint8_t *end = src + length;
+       while ( src < end )
+       {
+               *dest ++ = *src ++;
+               *dest ++ = *src ++;
+       }
+}
+
 mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_position frame_position )
 {
        // Create a frame to return
@@ -926,8 +951,17 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_pos
        w = result.w * width / result.nw;
        h = result.h * height / result.nh;
 
+       if ( y < 0 )
+       {
+               h = h + y;
+               y = 0;
+       }
+
+       if ( y + h > height )
+               h = height - y;
+
        x &= 0xfffffffe;
-       //w &= 0xfffffffe;
+       w &= 0xfffffffe;
 
        // Now we need to create a new destination image
        dest = mlt_pool_alloc( w * h * 2 );
@@ -939,7 +973,7 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_pos
 
        while ( q < r )
        {
-               memcpy( q, p, w * 2 );
+               inline_memcpy( q, p, w * 2 );
                q += w * 2;
                p += width * 2;
        }
@@ -973,6 +1007,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        // Get the image from the a frame
        mlt_frame_get_image( a_frame, image, format, width, height, 1 );
 
+       // Get the properties from the transition
+       mlt_properties properties = mlt_transition_properties( this );
+
        if ( b_frame != NULL )
        {
                // Get the properties of the a frame
@@ -981,9 +1018,6 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                // Get the properties of the b frame
                mlt_properties b_props = mlt_frame_properties( b_frame );
 
-               // Get the properties from the transition
-               mlt_properties properties = mlt_transition_properties( this );
-
                // Structures for geometry
                struct geometry_s result;
 
@@ -1019,7 +1053,8 @@ 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 );
-                       composite_line_fn line_fn = mlt_properties_get_int( properties, "_MMX" ) ? composite_line_yuv_mmx : composite_line_yuv;
+                       //composite_line_fn line_fn = mlt_properties_get_int( properties, "_MMX" ) ? composite_line_yuv_mmx : NULL;
+                       composite_line_fn line_fn = NULL;
 
                        for ( field = 0; field < ( progressive ? 1 : 2 ); field++ )
                        {