]> git.sesse.net Git - mlt/blobdiff - src/modules/core/transition_composite.c
Corrections to filter attachment and in/out point handling
[mlt] / src / modules / core / transition_composite.c
index 0119380ee906d8fb9a6c4bf20e7394cca3d7ae09..de2c464dae55c473f861b5e0431b33d4de52ce47 100644 (file)
@@ -159,10 +159,10 @@ static void geometry_calculate( struct geometry_s *output, struct geometry_s *in
        {
                output->nw = in->nw;
                output->nh = in->nh;
-               output->x = in->x + ( out->x - in->x ) * position;
-               output->y = in->y + ( out->y - in->y ) * position;
-               output->w = in->w + ( out->w - in->w ) * position;
-               output->h = in->h + ( out->h - in->h ) * position;
+               output->x = rint( in->x + ( out->x - in->x ) * position + 0.5 );
+               output->y = rint( in->y + ( out->y - in->y ) * position + 0.5 );
+               output->w = rint( in->w + ( out->w - in->w ) * position + 0.5 );
+               output->h = rint( in->h + ( out->h - in->h ) * position + 0.5 );
                output->mix = in->mix + ( out->mix - in->mix ) * position;
                output->distort = in->distort;
        }
@@ -177,15 +177,9 @@ static void geometry_calculate( struct geometry_s *output, struct geometry_s *in
                output->mix = out->mix;
                output->distort = out->distort;
        }
-
-       // DRD> These break on negative values. I do not think they are needed
-       // since yuv_composite takes care of YUYV group alignment
-       //output->x = ( int )floor( output->x ) & 0xfffffffe;
-       //output->w = ( int )floor( output->w ) & 0xfffffffe;
-       //output->sw &= 0xfffffffe;
 }
 
-void transition_destroy_keys( void *arg )
+static void transition_destroy_keys( void *arg )
 {
        struct geometry_s *ptr = arg;
        struct geometry_s *next = NULL;
@@ -275,9 +269,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;
 }
 
@@ -305,7 +296,7 @@ static int alignment_parse( char* align )
 static void alignment_calculate( struct geometry_s *geometry )
 {
        geometry->x += ( geometry->w - geometry->sw ) * geometry->halign / 2;
-       geometry->y += ( geometry->h - geometry->sh ) * geometry->valign / 2;
+       geometry->y += ( geometry->h - geometry->sh ) * geometry->valign;
 }
 
 /** Calculate the position for this frame.
@@ -547,10 +538,7 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        // Adjust to consumer scale
        int x = geometry.x * width_dest / geometry.nw;
        int y = geometry.y * height_dest / geometry.nh;
-
-       // Align x to a full YUYV group
-       x &= 0xfffffffe;
-       width_src &= 0xfffffffe;
+       int uneven = ( x & 1 );
 
        // optimization points - no work to do
        if ( width_src <= 0 || height_src <= 0 )
@@ -576,6 +564,7 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        {
                y_src = -y;
                height_src -= y_src;
+               y = 0;
        }
        
        // crop overlay below bottom edge of frame
@@ -622,6 +611,9 @@ 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 ( uneven )
+               p_src -= 2;
+
        // now do the compositing only to cropped extents
        if ( line_fn != NULL )
        {
@@ -848,7 +840,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
        *width = geometry->sw * *width / geometry->nw;
        *height = geometry->sh * *height / geometry->nh;
 
-       x &= 0xfffffffe;
+       //x = ( x | 1 ) ^ 1;
 
        // optimization points - no work to do
        if ( *width < 1 || *height < 1 )
@@ -863,7 +855,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 );
@@ -875,7 +867,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" );
@@ -883,6 +875,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
@@ -895,6 +891,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
@@ -940,8 +946,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;
 
-       x &= 0xfffffffe;
-       //w &= 0xfffffffe;
+       if ( y < 0 )
+       {
+               h = h + y;
+               y = 0;
+       }
+
+       if ( y + h > height )
+               h = height - y;
+
+       x = ( x | 1 ) ^ 1;
+       w = ( w | 1 ) ^ 1;
 
        // Now we need to create a new destination image
        dest = mlt_pool_alloc( w * h * 2 );
@@ -953,7 +968,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;
        }
@@ -987,6 +1002,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
@@ -995,9 +1013,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;