Corrects position and test_audio handling
[melted] / src / modules / core / transition_composite.c
index 4ffb3d5..57cf67d 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;
@@ -544,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 = ( x | 1 ) ^ 1;
-       width_src = ( width_src | 1 ) ^ 1;
+       int uneven = ( x & 1 );
 
        // optimization points - no work to do
        if ( width_src <= 0 || height_src <= 0 )
@@ -573,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
@@ -619,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 )
        {
@@ -845,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 = ( x | 1 ) ^ 1;
+       //x = ( x | 1 ) ^ 1;
 
        // optimization points - no work to do
        if ( *width < 1 || *height < 1 )
@@ -1027,20 +1022,45 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 
                // Do the calculation
                struct geometry_s *start = composite_calculate( &result, this, a_frame, position );
-               
+
+               // Get the image from the b frame
+               uint8_t *image_b = NULL;
+               int width_b = *width;
+               int height_b = *height;
+       
                // Optimisation - no compositing required
                if ( result.mix == 0 || ( result.w == 0 && result.h == 0 ) )
                        return 0;
 
+               // Need to keep the width/height of the a_frame on the b_frame for titling
+               if ( mlt_properties_get( a_props, "dest_width" ) == NULL )
+               {
+                       mlt_properties_set_int( a_props, "dest_width", *width );
+                       mlt_properties_set_int( a_props, "dest_height", *height );
+                       mlt_properties_set_int( b_props, "dest_width", *width );
+                       mlt_properties_set_int( b_props, "dest_height", *height );
+               }
+               else
+               {
+                       mlt_properties_set_int( b_props, "dest_width", mlt_properties_get_int( a_props, "dest_width" ) );
+                       mlt_properties_set_int( b_props, "dest_height", mlt_properties_get_int( a_props, "dest_height" ) );
+               }
+
                // 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_progressive", mlt_properties_get_double( a_props, "consumer_progressive" ) );
                mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
 
-               // Get the image from the b frame
-               uint8_t *image_b = NULL;
-               int width_b = *width;
-               int height_b = *height;
-               
+               // Special case for titling...
+               if ( mlt_properties_get_int( properties, "titles" ) )
+               {
+                       if ( mlt_properties_get( b_props, "rescale.interp" ) == NULL )
+                               mlt_properties_set( b_props, "rescale.interp", "nearest" );
+                       mlt_properties_set( properties, "fill", NULL );
+                       width_b = mlt_properties_get_int( a_props, "dest_width" );
+                       height_b = mlt_properties_get_int( a_props, "dest_height" );
+               }
+
                if ( get_b_frame_image( this, b_frame, &image_b, &width_b, &height_b, &result ) == 0 )
                {
                        uint8_t *dest = *image;