X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fgtk2%2Ffilter_rescale.c;h=14f3f28d4924abbb33575757d2bb48fd0d7132a3;hb=f00476101550ec7d8e863f6516aa83bc1b524570;hp=f061038c5efa0046865c0ff81fc015eb6f54d26c;hpb=36aad7b318537612374acfd3f626a8c1364ad95d;p=mlt diff --git a/src/modules/gtk2/filter_rescale.c b/src/modules/gtk2/filter_rescale.c index f061038c..14f3f28d 100644 --- a/src/modules/gtk2/filter_rescale.c +++ b/src/modules/gtk2/filter_rescale.c @@ -22,31 +22,24 @@ #include "pixops.h" #include +#include #include #include #include #include -/** Do it :-). -*/ - -static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) +static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format iformat, mlt_image_format oformat, int iwidth, int iheight, int owidth, int oheight ) { - if ( *width == 0 ) - *width = 720; - if ( *height == 0 ) - *height = 576; - - mlt_properties properties = mlt_frame_properties( this ); - int iwidth = *width; - int iheight = *height; - int owidth = *width; - int oheight = *height; - uint8_t *input = NULL; - + // Get the properties + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); + + // Get the requested interpolation method char *interps = mlt_properties_get( properties, "rescale.interp" ); + + // Convert to the GTK flag int interp = PIXOPS_INTERP_BILINEAR; + if ( strcmp( interps, "nearest" ) == 0 ) interp = PIXOPS_INTERP_NEAREST; else if ( strcmp( interps, "tiles" ) == 0 ) @@ -54,88 +47,89 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * else if ( strcmp( interps, "hyper" ) == 0 ) interp = PIXOPS_INTERP_HYPER; - mlt_frame_get_image( this, &input, format, &iwidth, &iheight, 0 ); - -#if 0 - // Determine maximum size within the aspect ratio: - double i_aspect_ratio = mlt_frame_get_aspect_ratio( this ); - // TODO: this needs to be provided q - #define o_aspect_ratio ( double )( 4.0 / 3.0 ) - - if ( ( owidth * i_aspect_ratio * o_aspect_ratio ) > owidth ) - oheight *= o_aspect_ratio / i_aspect_ratio; - else - owidth *= i_aspect_ratio * o_aspect_ratio; - - fprintf( stderr, "rescale: from %dx%d (%f) to %dx%d\n", iwidth, iheight, i_aspect_ratio, owidth, oheight ); -#endif - - // If width and height are correct, don't do anything - if ( strcmp( interps, "none" ) && input != NULL && ( iwidth != owidth || iheight != oheight ) ) + // Carry out the rescaling + if ( iformat == mlt_image_yuv422 && oformat == mlt_image_yuv422 ) { - if ( *format == mlt_image_yuv422 ) - { - // Create the output image - uint8_t *output = malloc( owidth * oheight * 2 ); + // Create the output image + uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 ); - // Calculate strides - int istride = iwidth * 2; - int ostride = owidth * 2; + // Calculate strides + int istride = iwidth * 2; + int ostride = owidth * 2; - yuv422_scale_simple( output, owidth, oheight, ostride, input, iwidth, iheight, istride, interp ); + yuv422_scale_simple( output, owidth, oheight, ostride, *image, iwidth, iheight, istride, interp ); - // Now update the frame - mlt_properties_set_data( properties, "image", output, owidth * oheight * 2, free, NULL ); - mlt_properties_set_int( properties, "width", owidth ); - mlt_properties_set_int( properties, "height", oheight ); + // Now update the frame + 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_rgb24 || *format == mlt_image_rgb24a ) + // Return the output + *image = output; + } + else if ( iformat == mlt_image_rgb24 || iformat == mlt_image_rgb24a ) + { + int bpp = (iformat == mlt_image_rgb24a ? 4 : 3 ); + + // Create the yuv image + uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 ); + + if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) ) { - int bpp = (*format == mlt_image_rgb24a ? 4 : 3 ); - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data( input, GDK_COLORSPACE_RGB, - (*format == mlt_image_rgb24a), 24, iwidth, iheight, + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data( *image, GDK_COLORSPACE_RGB, + ( iformat == mlt_image_rgb24a ), 8, iwidth, iheight, iwidth * bpp, NULL, NULL ); - GdkPixbuf *scaled = gdk_pixbuf_scale_simple( pixbuf, owidth, oheight, interp ); - - // Create the output image - uint8_t *output = malloc( owidth * oheight * bpp ); - - int i; - for ( i = 0; i < oheight; i++ ) - memcpy( output + i * owidth * bpp, - gdk_pixbuf_get_pixels( scaled ) + i * gdk_pixbuf_get_rowstride( scaled ), - gdk_pixbuf_get_width( scaled ) * bpp ); + GdkPixbuf *scaled = gdk_pixbuf_scale_simple( pixbuf, owidth, oheight, interp ); g_object_unref( pixbuf ); - g_object_unref( scaled ); - // Now update the frame - mlt_properties_set_data( properties, "image", output, owidth * oheight * bpp, free, NULL ); - mlt_properties_set_int( properties, "width", owidth ); - mlt_properties_set_int( properties, "height", oheight ); - - // Return the output - *image = output; + // Extract YUV422 and alpha + if ( bpp == 4 ) + { + // Allocate the alpha mask + 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 ), owidth, oheight, gdk_pixbuf_get_rowstride( scaled ), output, alpha ); + + mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL ); + } + else + { + // No alpha to extract + mlt_convert_rgb24_to_yuv422( gdk_pixbuf_get_pixels( scaled ), owidth, oheight, gdk_pixbuf_get_rowstride( scaled ), output ); + } + g_object_unref( scaled ); + } + else + { + // Extract YUV422 and alpha + if ( bpp == 4 ) + { + // Allocate the alpha mask + uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) ); + + // Convert the image and extract alpha + mlt_convert_rgb24a_to_yuv422( *image, owidth, oheight, owidth * 4, output, alpha ); + + mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL ); + } + else + { + // No alpha to extract + mlt_convert_rgb24_to_yuv422( *image, owidth, oheight, owidth * 3, output ); + } } - } - else - *image = input; - - return 0; -} -/** Filter processing. -*/ + // Now update the frame + 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 ); -static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) -{ - mlt_frame_push_get_image( frame, filter_get_image ); - mlt_properties_set( mlt_frame_properties( frame ), "rescale.interp", - mlt_properties_get( mlt_filter_properties( this ), "interpolation" ) ); - return frame; + *image = output; + } + + return 0; } /** Constructor for the filter. @@ -143,15 +137,22 @@ 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 ) + // Create a new scaler + mlt_filter this = mlt_factory_filter( "rescale", arg ); + + // If successful, then initialise it + 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" ); + // Get the properties + mlt_properties properties = MLT_FILTER_PROPERTIES( this ); + + // Set the inerpolation + mlt_properties_set( properties, "interpolation", arg == NULL ? "bilinear" : arg ); + + // Set the method + mlt_properties_set_data( properties, "method", filter_scale, 0, NULL, NULL ); } + return this; }