]> git.sesse.net Git - mlt/blobdiff - src/modules/core/transition_luma.c
Fix reading binary files on Windows.
[mlt] / src / modules / core / transition_luma.c
index 27aadeada1b0e5b2e5061de7f419da39dbd83b3e..224511f7de467a6599beb9723936bcf050619786 100644 (file)
 #include <ctype.h>
 #include <string.h>
 #include <math.h>
-
-/** Calculate the position for this frame.
-*/
-
-static float position_calculate( mlt_transition this, mlt_frame frame )
-{
-       // Get the in and out position
-       mlt_position in = mlt_transition_get_in( this );
-       mlt_position out = mlt_transition_get_out( this );
-
-       // Get the position of the frame
-       char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( this ), "_unique_id" );
-       mlt_position position = mlt_properties_get_position( MLT_FRAME_PROPERTIES( frame ), name );
-
-       // Now do the calcs
-       return ( float )( position - in ) / ( float )( out - in + 1 );
-}
-
-/** Calculate the field delta for this frame - position between two frames.
-*/
-
-static float delta_calculate( mlt_transition this, mlt_frame frame )
-{
-       // Get the in and out position
-       mlt_position in = mlt_transition_get_in( this );
-       mlt_position out = mlt_transition_get_out( this );
-
-       // Get the position of the frame
-       mlt_position position = mlt_frame_get_position( frame );
-
-       // Now do the calcs
-       float x = ( float )( position - in ) / ( float )( out - in + 1 );
-       float y = ( float )( position + 1 - in ) / ( float )( out - in + 1 );
-
-       return ( y - x ) / 2.0;
-}
+#include "transition_composite.h"
 
 static inline int dissolve_yuv( mlt_frame this, mlt_frame that, float weight, int width, int height )
 {
        int ret = 0;
+       int i = height + 1;
        int width_src = width, height_src = height;
        mlt_image_format format = mlt_image_yuv422;
        uint8_t *p_src, *p_dest;
-       uint8_t *p, *q;
-       uint8_t *limit;
        uint8_t *alpha_src;
        uint8_t *alpha_dst;
-
-       int32_t weigh = weight * ( 1 << 16 );
-       int32_t weigh_complement = ( 1 - weight ) * ( 1 << 16 );
+       int mix = weight * ( 1 << 16 );
 
        if ( mlt_properties_get( &this->parent, "distort" ) )
                mlt_properties_set( &that->parent, "distort", mlt_properties_get( &this->parent, "distort" ) );
-       mlt_properties_set_int( &that->parent, "consumer_deinterlace", mlt_properties_get_int( &this->parent, "consumer_deinterlace" ) );
        mlt_frame_get_image( this, &p_dest, &format, &width, &height, 1 );
        alpha_dst = mlt_frame_get_alpha_mask( this );
        mlt_frame_get_image( that, &p_src, &format, &width_src, &height_src, 0 );
@@ -90,16 +51,14 @@ static inline int dissolve_yuv( mlt_frame this, mlt_frame that, float weight, in
        // Pick the lesser of two evils ;-)
        width_src = width_src > width ? width : width_src;
        height_src = height_src > height ? height : height_src;
-       
-       p = p_dest;
-       q = alpha_dst;
-       limit = p_dest + height_src * width_src * 2;
 
-       while ( p < limit )
+       while ( --i )
        {
-               *p_dest++ = ( *p_src++ * weigh + *p++ * weigh_complement ) >> 16;
-               *p_dest++ = ( *p_src++ * weigh + *p++ * weigh_complement ) >> 16;
-               *alpha_dst++ = ( *alpha_src++ * weigh + *q++ * weigh_complement ) >> 16;
+               composite_line_yuv( p_dest, p_src, width_src, alpha_src, alpha_dst, mix, NULL, 0, 0 );
+               p_src += width_src << 1;
+               p_dest += width << 1;
+               alpha_src += width_src;
+               alpha_dst += width;
        }
 
        return ret;
@@ -139,7 +98,6 @@ static void luma_composite( mlt_frame a_frame, mlt_frame b_frame, int luma_width
 
        if ( mlt_properties_get( &a_frame->parent, "distort" ) )
                mlt_properties_set( &b_frame->parent, "distort", mlt_properties_get( &a_frame->parent, "distort" ) );
-       mlt_properties_set_int( &b_frame->parent, "consumer_deinterlace", mlt_properties_get_int( &a_frame->parent, "consumer_deinterlace" ) );
        mlt_frame_get_image( a_frame, &p_dest, &format_dest, &width_dest, &height_dest, 1 );
        mlt_frame_get_image( b_frame, &p_src, &format_src, &width_src, &height_src, 0 );
 
@@ -382,14 +340,15 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        // Correct width/height if not specified
        if ( luma_width == 0 || luma_height == 0 )
        {
-               luma_width = mlt_properties_get_int( a_props, "width" );
-               luma_height = mlt_properties_get_int( a_props, "height" );
+               luma_width = *width;
+               luma_height = *height;
        }
                
-       if ( resource != current_resource )
+       if ( resource && ( !current_resource || strcmp( resource, current_resource ) ) )
        {
                char temp[ 512 ];
                char *extension = strrchr( resource, '.' );
+               char *orig_resource = resource;
 
                if ( strchr( resource, '%' ) )
                {
@@ -408,7 +367,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                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
@@ -418,7 +377,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                // Set the transition properties
                                mlt_properties_set_int( properties, "width", luma_width );
                                mlt_properties_set_int( properties, "height", luma_height );
-                               mlt_properties_set( properties, "_resource", resource );
+                               mlt_properties_set( properties, "_resource", orig_resource );
                                mlt_properties_set_data( properties, "bitmap", luma_bitmap, luma_width * luma_height * 2, mlt_pool_release, NULL );
                        }
                }
@@ -469,7 +428,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                                        // Set the transition properties
                                        mlt_properties_set_int( properties, "width", luma_width );
                                        mlt_properties_set_int( properties, "height", luma_height );
-                                       mlt_properties_set( properties, "_resource", resource);
+                                       mlt_properties_set( properties, "_resource", orig_resource);
                                        mlt_properties_set_data( properties, "bitmap", luma_bitmap, luma_width * luma_height * 2, mlt_pool_release, NULL );
 
                                        // Cleanup the luma frame
@@ -483,8 +442,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        }
 
        // Arbitrary composite defaults
-       float mix = position_calculate( transition, a_frame );
-       float frame_delta = delta_calculate( transition, a_frame );
+       float mix = mlt_transition_get_progress( transition, a_frame );
+       float frame_delta = mlt_transition_get_progress_delta( transition, a_frame );
        float luma_softness = mlt_properties_get_double( properties, "softness" );
        int progressive = 
                        mlt_properties_get_int( a_props, "consumer_deinterlace" ) ||
@@ -494,28 +453,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        int reverse = mlt_properties_get_int( properties, "reverse" );
        int invert = mlt_properties_get_int( properties, "invert" );
 
-       if ( mlt_properties_get( a_props, "rescale.interp" ) == NULL || !strcmp( mlt_properties_get( a_props, "rescale.interp" ), "none" ) )
-               mlt_properties_set( a_props, "rescale.interp", "nearest" );
-
-       // Since we are the consumer of the b_frame, we must pass along this
-       // consumer property from the a_frame
-       if ( mlt_properties_get_double( a_props, "aspect_ratio" ) == 0.0 )
-               mlt_properties_set_double( a_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
-       if ( mlt_properties_get_double( b_props, "aspect_ratio" ) == 0.0 )
-               mlt_properties_set_double( b_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
-       mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
-
        // Honour the reverse here
        if ( mix >= 1.0 )
                mix -= floor( mix );
 
-       // Ensure we get scaling on the b_frame
-       if ( mlt_properties_get( b_props, "rescale.interp" ) == NULL || !strcmp( mlt_properties_get( b_props, "rescale.interp" ), "none" ) )
-               mlt_properties_set( b_props, "rescale.interp", mlt_properties_get( a_props, "rescale.interp" ) );
-       
-       if ( invert )
-               mlt_properties_set_int( b_props, "consumer_deinterlace", mlt_properties_get_int( a_props, "consumer_deinterlace") );
-
        if ( mlt_properties_get( properties, "fixed" ) )
                mix = mlt_properties_get_double( properties, "fixed" );
 
@@ -552,12 +493,6 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 
 static mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
 {
-       // Get a unique name to store the frame position
-       char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
-
-       // Assign the current position to the name
-       mlt_properties_set_position( MLT_FRAME_PROPERTIES( a_frame ), name, mlt_frame_get_position( a_frame ) );
-
        // Push the transition on to the frame
        mlt_frame_push_service( a_frame, transition );