]> git.sesse.net Git - mlt/blobdiff - src/modules/vmfx/filter_shape.c
move binary modules to libdir - affects MLT_REPOSITORY
[mlt] / src / modules / vmfx / filter_shape.c
index 1edaa1c1a0bcd1079fa03319971b972c07815c93..fdd33e435233bb34eaf30077ca83fe187d903473 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include "filter_shape.h"
+#include <framework/mlt.h>
 #include <string.h>
 #include <framework/mlt_factory.h>
 #include <framework/mlt_frame.h>
@@ -49,7 +49,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        int invert = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "invert" ) * 255;
 
        // Render the frame
-       if ( mlt_frame_get_image( this, image, format, width, height, writable ) == 0 )
+       if ( mlt_frame_get_image( this, image, format, width, height, writable ) == 0 && ( !use_luminance || ( int )mix != 1 ) )
        {
                // Get the alpha mask of the source
                uint8_t *alpha = mlt_frame_get_alpha_mask( this );
@@ -77,9 +77,11 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                        p ++;
                                }
                        }
-                       else if ( mix != 1.0 )
+                       else if ( ( int )mix != 1 )
                        {
                                uint8_t *q = mask_img;
+                               // Ensure softness tends to zero has mix tends to 1
+                               softness *= ( 1.0 - mix );
                                while( size -- )
                                {
                                        a = ( ( double )*q - 16 ) / 235.0;
@@ -102,6 +104,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 {
        // Obtain the shape instance
        char *resource = mlt_properties_get( MLT_FILTER_PROPERTIES( this ), "resource" );
+       char *last_resource = mlt_properties_get( MLT_FILTER_PROPERTIES( this ), "_resource" );
        mlt_producer producer = mlt_properties_get_data( MLT_FILTER_PROPERTIES( this ), "instance", NULL );
 
        // Get the key framed values
@@ -120,15 +123,48 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
        {
                in = mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "in" );
                out = mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "out" );
+               position -= in;
        }
 
        // Duration of the shape
        length = out - in + 1;
 
        // If we haven't created the instance or it's changed
-       if ( producer == NULL || strcmp( resource, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "resource" ) ) )
+       if ( producer == NULL || strcmp( resource, last_resource ) )
        {
-               producer = mlt_factory_producer( NULL, resource );
+               char temp[ 512 ];
+               char *extension = strrchr( resource, '.' );
+
+               // Store the last resource now
+               mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "_resource", resource );
+
+               // This is a hack - the idea is that we can indirectly reference the
+               // luma modules pgm or png images by a short cut like %luma01.pgm - we then replace
+               // the % with the full path to the image and use it if it exists, if not, check for
+               // the file ending in a .png, and failing that, default to a fade in
+               if ( strchr( resource, '%' ) )
+               {
+                       FILE *test;
+                       sprintf( temp, "%s/lumas/%s/%s", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ), strchr( resource, '%' ) + 1 );
+                       test = fopen( temp, "r" );
+
+                       if ( test == NULL )
+                       {
+                               strcat( temp, ".png" );
+                               test = fopen( temp, "r" );
+                       }
+
+                       if ( test )
+                               fclose( test ); 
+                       else
+                               strcpy( temp, "colour:0x00000080" );
+
+                       resource = temp;
+                       extension = strrchr( resource, '.' );
+               }
+
+               mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( this ) );
+               producer = mlt_factory_producer( profile, NULL, resource );
                if ( producer != NULL )
                        mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" );
                mlt_properties_set_data( MLT_FILTER_PROPERTIES( this ), "instance", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
@@ -164,7 +200,10 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
                        mlt_deque_push_back_double( MLT_FRAME_IMAGE_STACK( frame ), alpha_mix / 100.0 );
                        mlt_frame_push_get_image( frame, filter_get_image );
                        if ( mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "audio_match" ) )
+                       {
+                               mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "meta.mixdown", 1 );
                                mlt_properties_set_double( MLT_FRAME_PROPERTIES( frame ), "meta.volume", alpha_mix / 100.0 );
+                       }
                }
        }
 
@@ -174,7 +213,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 /** Constructor for the filter.
 */
 
-mlt_filter filter_shape_init( char *arg )
+mlt_filter filter_shape_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
        mlt_filter this = mlt_filter_new( );
        if ( this != NULL )