Prevent potential divide-by-zero errors in sdl_still consumer.
[melted] / src / modules / sdl / consumer_sdl_still.c
index 71e698b..3efd8f4 100644 (file)
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "consumer_sdl.h"
+#include <framework/mlt_consumer.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_deque.h>
 #include <framework/mlt_factory.h>
@@ -72,13 +72,13 @@ static void consumer_sdl_event( mlt_listener listener, mlt_properties owner, mlt
        via the argument, but keep it simple.
 */
 
-mlt_consumer consumer_sdl_still_init( char *arg )
+mlt_consumer consumer_sdl_still_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
        // Create the consumer object
        consumer_sdl this = calloc( sizeof( struct consumer_sdl_s ), 1 );
 
        // If no malloc'd and consumer init ok
-       if ( this != NULL && mlt_consumer_init( &this->parent, this ) == 0 )
+       if ( this != NULL && mlt_consumer_init( &this->parent, this, profile ) == 0 )
        {
                // Get the parent consumer object
                mlt_consumer parent = &this->parent;
@@ -154,7 +154,8 @@ static int consumer_start( mlt_consumer parent )
                // Attach a colour space converter
                if ( !this->filtered )
                {
-                       mlt_filter filter = mlt_factory_filter( "avcolour_space", NULL );
+                       mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( parent ) );
+                       mlt_filter filter = mlt_factory_filter( profile, "avcolour_space", NULL );
                        mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "forced", mlt_image_yuv422 );
                        mlt_service_attach( MLT_CONSUMER_SERVICE( parent ), filter );
                        mlt_filter_close( filter );
@@ -192,7 +193,6 @@ static int consumer_start( mlt_consumer parent )
                        if ( SDL_GetVideoSurface( ) != NULL )
                        {
                                this->sdl_screen = SDL_GetVideoSurface( );
-                               consumer_get_dimensions( &this->window_width, &this->window_height );
                        }
                }
 
@@ -252,6 +252,7 @@ static void sdl_unlock_display( )
 static inline void display_1( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
 {
        // Generate the affine transform scaling values
+       if ( rect.w == 0 || rect.h == 0 ) return;
        int scale_width = ( width << 16 ) / rect.w;
        int scale_height = ( height << 16 ) / rect.h;
        int stride = width * 3;
@@ -281,6 +282,7 @@ static inline void display_1( SDL_Surface *screen, SDL_Rect rect, uint8_t *image
 static inline void display_2( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
 {
        // Generate the affine transform scaling values
+       if ( rect.w == 0 || rect.h == 0 ) return;
        int scale_width = ( width << 16 ) / rect.w;
        int scale_height = ( height << 16 ) / rect.h;
        int stride = width * 3;
@@ -310,6 +312,7 @@ static inline void display_2( SDL_Surface *screen, SDL_Rect rect, uint8_t *image
 static inline void display_3( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
 {
        // Generate the affine transform scaling values
+       if ( rect.w == 0 || rect.h == 0 ) return;
        int scale_width = ( width << 16 ) / rect.w;
        int scale_height = ( height << 16 ) / rect.h;
        int stride = width * 3;
@@ -343,6 +346,7 @@ static inline void display_3( SDL_Surface *screen, SDL_Rect rect, uint8_t *image
 static inline void display_4( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
 {
        // Generate the affine transform scaling values
+       if ( rect.w == 0 || rect.h == 0 ) return;
        int scale_width = ( width << 16 ) / rect.w;
        int scale_height = ( height << 16 ) / rect.h;
        int stride = width * 3;
@@ -431,6 +435,8 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
                if ( consumer_get_dimensions( &this->window_width, &this->window_height ) )
                        this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
+               uint32_t color = mlt_properties_get_int( this->properties, "window_background" );
+               SDL_FillRect( this->sdl_screen, NULL, color >> 8 );
                changed = 1;
        }
        else
@@ -492,8 +498,6 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
        
        if ( !mlt_consumer_is_stopped( &this->parent ) && SDL_GetVideoSurface( ) != NULL && this->sdl_screen != NULL && this->sdl_screen->pixels != NULL )
        {
-               memset( this->sdl_screen->pixels, 0, this->window_width * this->window_height * this->sdl_screen->format->BytesPerPixel );
-
                switch( this->sdl_screen->format->BytesPerPixel )
                {
                        case 1: