]> git.sesse.net Git - mlt/blobdiff - src/modules/fezzik/producer_fezzik.c
producer_fezzik.c: do not use the swscale filter on images wider than 2048 loaded...
[mlt] / src / modules / fezzik / producer_fezzik.c
index 22c3510bb4d7236f74e5b9b013016d56726cc233..816c1bd70a2210f44a904f5acdf6049bec6fb0db 100644 (file)
@@ -3,35 +3,34 @@
  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "producer_fezzik.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <fnmatch.h>
+#include <assert.h>
 
 #include <framework/mlt.h>
 
 static mlt_properties dictionary = NULL;
 static mlt_properties normalisers = NULL;
 
-static mlt_producer create_from( char *file, char *services )
+static mlt_producer create_from( mlt_profile profile, char *file, char *services )
 {
        mlt_producer producer = NULL;
        char *temp = strdup( services );
@@ -41,7 +40,7 @@ static mlt_producer create_from( char *file, char *services )
                char *p = strchr( service, ',' );
                if ( p != NULL )
                        *p ++ = '\0';
-               producer = mlt_factory_producer( service, file );
+               producer = mlt_factory_producer( profile, service, file );
                service = p;
        }
        while ( producer == NULL && service != NULL );
@@ -49,7 +48,7 @@ static mlt_producer create_from( char *file, char *services )
        return producer;
 }
 
-static mlt_producer create_producer( char *file )
+static mlt_producer create_producer( mlt_profile profile, char *file )
 {
        mlt_producer result = NULL;
 
@@ -60,7 +59,7 @@ static mlt_producer create_producer( char *file )
                char *service = temp;
                char *resource = strchr( temp, ':' );
                *resource ++ = '\0';
-               result = mlt_factory_producer( service, resource );
+               result = mlt_factory_producer( profile, service, resource );
                free( temp );
        }
 
@@ -75,7 +74,7 @@ static mlt_producer create_producer( char *file )
                if ( dictionary == NULL )
                {
                        char temp[ 1024 ];
-                       sprintf( temp, "%s/fezzik.dict", mlt_factory_prefix( ) );
+                       sprintf( temp, "%s/fezzik.dict", mlt_environment( "MLT_DATA" ) );
                        dictionary = mlt_properties_load( temp );
                        mlt_factory_register_for_clean_up( dictionary, ( mlt_destructor )mlt_properties_close );
                }
@@ -92,7 +91,7 @@ static mlt_producer create_producer( char *file )
                {
                        char *name = mlt_properties_get_name( dictionary, i );
                        if ( fnmatch( name, lookup, 0 ) == 0 )
-                               result = create_from( file, mlt_properties_get_value( dictionary, i ) );
+                               result = create_from( profile, file, mlt_properties_get_value( dictionary, i ) );
                }
 
                free( lookup );
@@ -100,21 +99,28 @@ static mlt_producer create_producer( char *file )
 
        // Finally, try just loading as service
        if ( result == NULL )
-               result = mlt_factory_producer( file, NULL );
+               result = mlt_factory_producer( profile, file, NULL );
 
        return result;
 }
 
-static void create_filter( mlt_producer producer, char *effect, int *created )
+static void create_filter( mlt_profile profile, mlt_producer producer, char *effect, int *created )
 {
+       // The swscale filter can not handle images with a width > 2048 and the
+       // sdl_image producer does not scale on its own
+       if ( strncmp( effect, "swscale", 7 ) == 0 &&
+            mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "_real_width" ) > 2048 &&
+            strcmp( mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "mlt_service" ), "sdl_image" ) == 0 )
+               return;
+
        char *id = strdup( effect );
        char *arg = strchr( id, ':' );
        if ( arg != NULL )
                *arg ++ = '\0';
-       mlt_filter filter = mlt_factory_filter( id, arg );
+       mlt_filter filter = mlt_factory_filter( profile, id, arg );
        if ( filter != NULL )
        {
-               mlt_properties_set_int( mlt_filter_properties( filter ), "_fezzik", 1 );
+               mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
                mlt_producer_attach( producer, filter );
                mlt_filter_close( filter );
                *created = 1;
@@ -122,7 +128,7 @@ static void create_filter( mlt_producer producer, char *effect, int *created )
        free( id );
 }
 
-static void attach_normalisers( mlt_producer producer )
+static void attach_normalisers( mlt_profile profile, mlt_producer producer )
 {
        // Loop variable
        int i;
@@ -134,7 +140,7 @@ static void attach_normalisers( mlt_producer producer )
        if ( normalisers == NULL )
        {
                char temp[ 1024 ];
-               sprintf( temp, "%s/fezzik.ini", mlt_factory_prefix( ) );
+               sprintf( temp, "%s/fezzik.ini", mlt_environment( "MLT_DATA" ) );
                normalisers = mlt_properties_load( temp );
                mlt_factory_register_for_clean_up( normalisers, ( mlt_destructor )mlt_properties_close );
        }
@@ -147,28 +153,30 @@ static void attach_normalisers( mlt_producer producer )
                char *value = mlt_properties_get_value( normalisers, i );
                mlt_tokeniser_parse_new( tokeniser, value, "," );
                for ( j = 0; !created && j < mlt_tokeniser_count( tokeniser ); j ++ )
-                       create_filter( producer, mlt_tokeniser_get_string( tokeniser, j ), &created );
+                       create_filter( profile, producer, mlt_tokeniser_get_string( tokeniser, j ), &created );
        }
 
        // Close the tokeniser
        mlt_tokeniser_close( tokeniser );
 }
 
-mlt_producer producer_fezzik_init( char *arg )
+mlt_producer producer_fezzik_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
        // Create the producer 
        mlt_producer producer = NULL;
        mlt_properties properties = NULL;
 
        if ( arg != NULL )
-               producer = create_producer( arg );
+               producer = create_producer( profile, arg );
 
        if ( producer != NULL )
-               properties = mlt_producer_properties( producer );
+               properties = MLT_PRODUCER_PROPERTIES( producer );
 
        // Attach filters if we have a producer and it isn't already westley'd :-)
-       if ( producer != NULL && mlt_properties_get( properties, "westley" ) == NULL )
-               attach_normalisers( producer );
+       if ( producer != NULL && mlt_properties_get( properties, "westley" ) == NULL && \
+               mlt_properties_get( properties, "_westley" ) == NULL && \
+               mlt_properties_get( properties, "fezzik_normalised" ) == NULL )
+               attach_normalisers( profile, producer );
 
        // Now make sure we don't lose our identity
        if ( properties != NULL )