more sdl/consumer tuning and demo updates
[melted] / src / modules / gtk2 / filter_rescale.c
index 049e68a..c57e33d 100644 (file)
@@ -38,6 +38,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                *width = 720;
        if ( *height == 0 )
                *height = 576;
+       if ( *width < 2 || *height < 6 )
+               return 1;
 
        mlt_properties properties = mlt_frame_properties( this );
        int iwidth = *width;
@@ -75,8 +77,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                if ( *format == mlt_image_yuv422 && strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                {
                        // Create the output image
-                       void *release = NULL;
-                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+                       uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                        // Calculate strides
                        int istride = iwidth * 2;
@@ -85,21 +86,26 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        yuv422_scale_simple( output, owidth, oheight, ostride, input, iwidth, iheight, istride, interp );
                
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );
 
                        // Return the output
                        *image = output;
                }
+               else if ( *format == mlt_image_yuv422 && !strcmp( interps, "none" ) )
+               {
+                       // Do nothing
+                       *width = iwidth;
+                       *height = iheight;
+                       *image = input;
+               }
                else if ( *format == mlt_image_rgb24 || *format == mlt_image_rgb24a )
                {
                        int bpp = (*format == mlt_image_rgb24a ? 4 : 3 );
                        
                        // Create the yuv image
-                       void *release = NULL;
-                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+                       uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                        if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                        {
@@ -114,8 +120,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       void *alpha_release = NULL;
-                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
+                                       uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( scaled ),
@@ -123,8 +128,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  gdk_pixbuf_get_rowstride( scaled ),
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
                                }
                                else
                                {
@@ -142,8 +146,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       void *alpha_release = NULL;
-                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
+                                       uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( input,
@@ -151,8 +154,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  owidth * 4,
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
                                }
                                else
                                {
@@ -165,8 +167,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        }
 
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );
 
@@ -213,15 +214,11 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 
 mlt_filter filter_rescale_init( char *arg )
 {
-       mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 );
-       if ( mlt_filter_init( this, this ) == 0 )
+       mlt_filter this = mlt_filter_new( );
+       if ( this != NULL )
        {
                this->process = filter_process;
-               if ( arg != NULL )
-                       mlt_properties_set( mlt_filter_properties( this ), "interpolation", arg );
-               else
-                       mlt_properties_set( mlt_filter_properties( this ), "interpolation", "bilinear" );
+               mlt_properties_set( mlt_filter_properties( this ), "interpolation", arg == NULL ? "bilinear" : arg );
        }
        return this;
 }
-