X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fgtk2%2Ffilter_rescale.c;h=92b2b7b6713c9de90daae075afd9204f622f9d82;hb=f4fef6a77643c2ec85e00f0afc28d88fe0fbd4a9;hp=85bb8cdd79ca8dd9d1173ef7e0f701934ade7139;hpb=8a3795b090723264c973d274eedc28da480e76fd;p=melted diff --git a/src/modules/gtk2/filter_rescale.c b/src/modules/gtk2/filter_rescale.c index 85bb8cd..92b2b7b 100644 --- a/src/modules/gtk2/filter_rescale.c +++ b/src/modules/gtk2/filter_rescale.c @@ -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; @@ -63,8 +65,17 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * } // Let the producer know what we are actually requested to obtain - mlt_properties_set_int( properties, "rescale_width", *width ); - mlt_properties_set_int( properties, "rescale_height", *height ); + if ( *format == mlt_image_yuv422 && strcmp( interps, "none" ) ) + { + mlt_properties_set_int( properties, "rescale_width", *width ); + mlt_properties_set_int( properties, "rescale_height", *height ); + } + else + { + // When no scaling is requested, revert the requested dimensions if possible + mlt_properties_set_int( properties, "rescale_width", ( iwidth / 2 ) * 2 ); + mlt_properties_set_int( properties, "rescale_height", ( iheight / 2 ) * 2 ); + } // Get the image as requested mlt_frame_get_image( this, &input, format, &iwidth, &iheight, writable ); @@ -75,8 +86,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 - // IRRIGATE ME - uint8_t *output = malloc( owidth * ( oheight + 1 ) * 2 ); + uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 ); // Calculate strides int istride = iwidth * 2; @@ -85,20 +95,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", output, owidth * ( oheight + 1 ) * 2, free, 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 - // IRRIGATE ME - uint8_t *output = malloc( owidth * ( oheight + 1 ) * 2 ); + uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 ); if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) ) { @@ -113,8 +129,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * if ( bpp == 4 ) { // Allocate the alpha mask - // IRRIGATE ME - uint8_t *alpha = malloc( owidth * ( oheight + 1 ) ); + 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 ), @@ -122,7 +137,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", alpha, owidth * ( oheight + 1 ), free, NULL ); + mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL ); } else { @@ -140,8 +155,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * if ( bpp == 4 ) { // Allocate the alpha mask - // IRRIGATE ME - uint8_t *alpha = malloc( owidth * ( oheight + 1 ) ); + uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) ); // Convert the image and extract alpha mlt_convert_rgb24a_to_yuv422( input, @@ -149,7 +163,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", alpha, owidth * ( oheight + 1 ), free, NULL ); + mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL ); } else { @@ -162,7 +176,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", output, owidth * ( oheight + 1 ) * 2, free, 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 ); @@ -209,15 +223,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; } -