*width = 720;
if ( *height == 0 )
*height = 576;
+ if ( *width < 2 || *height < 6 )
+ return 1;
mlt_properties properties = mlt_frame_properties( this );
int iwidth = *width;
uint8_t *input = NULL;
char *interps = mlt_properties_get( properties, "rescale.interp" );
int interp = PIXOPS_INTERP_BILINEAR;
- double i_aspect_ratio = mlt_frame_get_aspect_ratio( this );
- double o_aspect_ratio = mlt_properties_get_double( properties, "consumer_aspect_ratio" );
if ( strcmp( interps, "nearest" ) == 0 )
interp = PIXOPS_INTERP_NEAREST;
else if ( strcmp( interps, "hyper" ) == 0 )
interp = PIXOPS_INTERP_HYPER;
- mlt_frame_get_image( this, &input, format, &iwidth, &iheight, writable );
-
- if ( o_aspect_ratio != 0 && o_aspect_ratio != i_aspect_ratio && mlt_properties_get( properties, "distort" ) == NULL )
+ // If real_width/height exist, we want that as minimum information
+ if ( mlt_properties_get_int( properties, "real_width" ) )
{
- int temp_width = i_aspect_ratio / o_aspect_ratio * owidth + 0.5;
+ iwidth = mlt_properties_get_int( properties, "real_width" );
+ iheight = mlt_properties_get_int( properties, "real_height" );
+ }
- // Determine maximum size within the aspect ratio:
- if ( temp_width > owidth )
- if ( i_aspect_ratio > o_aspect_ratio )
- oheight = o_aspect_ratio / i_aspect_ratio * oheight + 0.5;
- else
- oheight = i_aspect_ratio / o_aspect_ratio * oheight + 0.5;
- else
- owidth = temp_width;
-
- // Tell frame we have conformed the aspect to the consumer
- mlt_frame_set_aspect_ratio( this, o_aspect_ratio );
+ // Let the producer know what we are actually requested to obtain
+ if ( *format == mlt_image_yuv422 && strcmp( interps, "none" ) )
+ {
+ mlt_properties_set_int( properties, "rescale_width", *width );
+ mlt_properties_set_int( properties, "rescale_height", *height );
}
- //fprintf( stderr, "rescale: from %dx%d (aspect %f) to %dx%d (aspect %f)\n", iwidth, iheight, i_aspect_ratio, owidth, oheight, o_aspect_ratio );
+ 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 );
if ( input != NULL )
{
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;
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 ) )
{
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 ),
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
{
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,
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
{
}
// 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 );
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;
}
-