]> git.sesse.net Git - mlt/blobdiff - src/modules/core/transition_composite.c
Fix reading binary files on Windows.
[mlt] / src / modules / core / transition_composite.c
index 222ce002d9e59f0793ad7486d16025a590b41c55..9b9eada2d55c224e29650e13f37b2a640f47706d 100644 (file)
@@ -355,7 +355,7 @@ static void luma_read_yuv422( uint8_t *image, uint16_t **map, int width, int hei
 
 static inline int calculate_mix( uint16_t *luma, int j, int softness, int weight, int alpha, uint32_t step )
 {
-       return ( ( luma ? smoothstep( luma[ j ], luma[ j ] + softness, step ) : weight ) * alpha ) >> 8;
+       return ( ( luma ? smoothstep( luma[ j ], luma[ j ] + softness, step ) : weight ) * ( alpha + 1 ) ) >> 8;
 }
 
 static inline uint8_t sample_mix( uint8_t dest, uint8_t src, int mix )
@@ -366,7 +366,7 @@ static inline uint8_t sample_mix( uint8_t dest, uint8_t src, int mix )
 /** Composite a source line over a destination line
 */
 #if defined(USE_SSE) && defined(ARCH_X86_64)
-#include "composite_line_yuv_sse2_simple.c"
+void composite_line_yuv_sse2_simple(uint8_t *dest, uint8_t *src, int width, uint8_t *alpha_b, uint8_t *alpha_a, int weight);
 #endif
 
 void composite_line_yuv( uint8_t *dest, uint8_t *src, int width, uint8_t *alpha_b, uint8_t *alpha_a, int weight, uint16_t *luma, int soft, uint32_t step )
@@ -460,7 +460,7 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        int stride_src = geometry.sw * bpp;
        int stride_dest = width_dest * bpp;
        int i_softness = ( 1 << 16 ) * softness;
-       int weight = ( ( ( 1 << 16 ) - 1 ) * geometry.item.mix + 50 ) / 100;
+       int weight = ( ( 1 << 16 ) * geometry.item.mix + 50 ) / 100;
        uint32_t luma_step = ( ( ( 1 << 16 ) - 1 ) * geometry.item.mix + 50 ) / 100 * ( 1.0 + softness );
 
        // Adjust to consumer scale
@@ -521,7 +521,7 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        p_src += x_src * bpp + y_src * stride_src;
 
        // offset pointer into frame buffer based upon positive coordinates only!
-       p_dest += ( x < 0 ? 0 : x ) * bpp + ( y < 0 ? 0 : y ) * stride_dest;
+       p_dest += x * bpp + y * stride_dest;
 
        // offset pointer into alpha channel based upon cropping
        alpha_b += x_src + y_src * stride_src / bpp;
@@ -561,7 +561,6 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint
        if ( uneven_x != uneven_x_src )
        {
                p_src += 2;
-               width_src -= 2;
                alpha_b += 1;
        }
 
@@ -675,7 +674,7 @@ static uint16_t* get_luma( mlt_transition self, mlt_properties properties, int w
                        if ( extension != NULL && strcmp( extension, ".pgm" ) == 0 )
                        {
                                // Open PGM
-                               FILE *f = fopen( resource, "r" );
+                               FILE *f = fopen( resource, "rb" );
                                if ( f != NULL )
                                {
                                        // Load from PGM
@@ -766,17 +765,15 @@ static int get_b_frame_image( mlt_transition self, mlt_frame b_frame, uint8_t **
        mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
        mlt_properties properties = MLT_TRANSITION_PROPERTIES( self );
        uint8_t resize_alpha = mlt_properties_get_int( b_props, "resize_alpha" );
-       double consumer_ar = mlt_profile_sar( mlt_service_profile( MLT_TRANSITION_SERVICE(self) ) );
+       double output_ar = mlt_profile_sar( mlt_service_profile( MLT_TRANSITION_SERVICE(self) ) );
 
        // 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
        if ( mlt_properties_get( properties, "crop" ) )
        {
-               int real_width = get_value( b_props, "real_width", "width" );
-               int real_height = get_value( b_props, "real_height", "height" );
+               int real_width = get_value( b_props, "meta.media.width", "width" );
+               int real_height = get_value( b_props, "meta.media.height", "height" );
                double input_ar = mlt_properties_get_double( b_props, "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 );
                int scaled_height = real_height;
                geometry->sw = scaled_width;
@@ -788,16 +785,14 @@ static int get_b_frame_image( mlt_transition self, mlt_frame b_frame, uint8_t **
                // Adjust b_frame pixel aspect
                int normalised_width = geometry->item.w;
                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" );
+               int real_width = get_value( b_props, "meta.media.width", "width" );
+               int real_height = get_value( b_props, "meta.media.height", "height" );
                double input_ar = mlt_properties_get_double( b_props, "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 );
                int scaled_height = real_height;
-// fprintf(stderr, "%s: scaled %dx%d norm %dx%d real %dx%d output_ar %f => %f\n", __FILE__,
+// fprintf(stderr, "%s: scaled %dx%d norm %dx%d real %dx%d output_ar %f\n", __FILE__,
 // scaled_width, scaled_height, normalised_width, normalised_height, real_width, real_height,
-// background_ar, output_ar);
+// output_ar);
 
                // Now ensure that our images fit in the normalised frame
                if ( scaled_width > normalised_width )
@@ -925,8 +920,9 @@ static mlt_geometry composite_calculate( mlt_transition self, struct geometry_s
        mlt_geometry start = mlt_properties_get_data( properties, "geometries", NULL );
 
        // Obtain the normalised width and height from the a_frame
-       int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
-       int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
+       mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( self ) );
+       int normalised_width = profile->width;
+       int normalised_height = profile->height;
 
        char *name = mlt_properties_get( properties, "_unique_id" );
        char key[ 256 ];
@@ -1140,8 +1136,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 
                // Get the image from the b frame
                uint8_t *image_b = NULL;
-               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" );
+               mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( self ) );
+               int width_b = *width > 0 ? *width : profile->width;
+               int height_b = *height > 0 ? *height : profile->height;
        
                // Vars for alphas
                uint8_t *alpha_a = NULL;
@@ -1329,7 +1326,7 @@ static mlt_frame composite_process( mlt_transition self, mlt_frame a_frame, mlt_
 
 mlt_transition transition_composite_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
-       mlt_transition self = calloc( sizeof( struct mlt_transition_s ), 1 );
+       mlt_transition self = calloc( 1, sizeof( struct mlt_transition_s ) );
        if ( self != NULL && mlt_transition_init( self, NULL ) == 0 )
        {
                mlt_properties properties = MLT_TRANSITION_PROPERTIES( self );