X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fsdl%2Fproducer_sdl_image.c;h=9c3bd8b73756580e996c26afac44f050129948b3;hb=263782cae3c9917d957f71cde4b9a63080f8da9f;hp=ea913ba328cc2942cb53ce3fb00a086bebf06353;hpb=bf3264b9e340ba5c11cbf59835a8af3db94e0cc2;p=melted diff --git a/src/modules/sdl/producer_sdl_image.c b/src/modules/sdl/producer_sdl_image.c index ea913ba..9c3bd8b 100644 --- a/src/modules/sdl/producer_sdl_image.c +++ b/src/modules/sdl/producer_sdl_image.c @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "producer_sdl_image.h" +#include #include #include @@ -87,7 +87,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **image, mlt_image_forma return 0; } -static int filter_files( struct dirent *de ) +static int filter_files( const struct dirent *de ) { return de->d_name[ 0 ] != '.'; } @@ -150,23 +150,26 @@ static SDL_Surface *load_image( mlt_producer producer ) mlt_properties_set_data( properties, "_surface", surface, 0, ( mlt_destructor )SDL_FreeSurface, 0 ); } - image_idx = ( int )floor( ( double )position / ttl ) % mlt_properties_count( filenames ); - this_resource = mlt_properties_get_value( filenames, image_idx ); - - if ( last_resource == NULL || strcmp( last_resource, this_resource ) ) + if ( mlt_properties_count( filenames ) ) { - surface = IMG_Load( this_resource ); - if ( surface != NULL ) + image_idx = ( int )floor( ( double )position / ttl ) % mlt_properties_count( filenames ); + this_resource = mlt_properties_get_value( filenames, image_idx ); + + if ( last_resource == NULL || strcmp( last_resource, this_resource ) ) + { + surface = IMG_Load( this_resource ); + if ( surface != NULL ) + { + surface->refcount ++; + mlt_properties_set_data( properties, "_surface", surface, 0, ( mlt_destructor )SDL_FreeSurface, 0 ); + mlt_properties_set( properties, "_last_resource", this_resource ); + } + } + else if ( surface != NULL ) { surface->refcount ++; - mlt_properties_set_data( properties, "_surface", surface, 0, ( mlt_destructor )SDL_FreeSurface, 0 ); - mlt_properties_set( properties, "_last_resource", this_resource ); } } - else if ( surface != NULL ) - { - surface->refcount ++; - } return surface; } @@ -174,7 +177,7 @@ static SDL_Surface *load_image( mlt_producer producer ) static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) { // Generate a frame - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); if ( *frame != NULL ) { @@ -217,7 +220,7 @@ static void producer_close( mlt_producer producer ) free( producer ); } -mlt_producer producer_sdl_image_init( char *file ) +mlt_producer producer_sdl_image_init( mlt_profile profile, mlt_service_type type, const char *id, char *file ) { mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) ); if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 ) @@ -236,6 +239,17 @@ mlt_producer producer_sdl_image_init( char *file ) mlt_properties_set_int( properties, "ttl", 25 ); mlt_properties_set_int( properties, "progressive", 1 ); + // Validate the resource + SDL_Surface *surface = NULL; + if ( file && ( surface = load_image( producer ) ) ) + { + SDL_FreeSurface( surface ); + } + else + { + producer_close( producer ); + producer = NULL; + } return producer; } free( producer );