#include <framework/mlt_filter.h>
#include <framework/mlt_frame.h>
#include <framework/mlt_log.h>
+#include <framework/mlt_profile.h>
#include <stdio.h>
#include <string.h>
* rgb24a -> yuv422
*/
-typedef int ( *image_scaler )( mlt_frame this, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight );
+typedef int ( *image_scaler )( mlt_frame frame, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight );
-static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight )
+static int filter_scale( mlt_frame frame, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight )
{
- // Get the properties
- mlt_properties properties = MLT_FRAME_PROPERTIES( this );
-
// Create the output image
uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
}
// 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 );
-
+ mlt_frame_set_image( frame, output, owidth * ( oheight + 1 ) * 2, mlt_pool_release );
*image = output;
+
return 0;
}
-static void scale_alpha( mlt_frame this, int iwidth, int iheight, int owidth, int oheight )
+static void scale_alpha( mlt_frame frame, int iwidth, int iheight, int owidth, int oheight )
{
// Scale the alpha
uint8_t *output = NULL;
- uint8_t *input = mlt_frame_get_alpha_mask( this );
+ uint8_t *input = mlt_frame_get_alpha_mask( frame );
if ( input != NULL )
{
}
// Set it back on the frame
- mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output, owidth * oheight, mlt_pool_release, NULL );
+ mlt_frame_set_alpha( frame, output, owidth * oheight, mlt_pool_release );
}
}
/** 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_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
{
+ int error = 0;
+
// Get the frame properties
- mlt_properties properties = MLT_FRAME_PROPERTIES( this );
+ mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
// Get the filter from the stack
- mlt_filter filter = mlt_frame_pop_service( this );
+ mlt_filter filter = mlt_frame_pop_service( frame );
// Get the filter properties
mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
// Correct Width/height if necessary
if ( *width == 0 || *height == 0 )
{
- *width = mlt_properties_get_int( properties, "normalised_width" );
- *height = mlt_properties_get_int( properties, "normalised_height" );
+ mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
+ *width = profile->width;
+ *height = profile->height;
}
// There can be problems with small images - avoid them (by hacking - gah)
{
int iwidth = *width;
int iheight = *height;
- int owidth = *width;
- int oheight = *height;
+ double factor = mlt_properties_get_double( filter_properties, "factor" );
+ factor = factor > 0 ? factor : 1.0;
+ int owidth = *width * factor;
+ int oheight = *height * factor;
char *interps = mlt_properties_get( properties, "rescale.interp" );
// Default from the scaler if not specifed on the frame
mlt_properties_set( properties, "rescale.interp", interps );
}
- // If real_width/height exist, we want that as minimum information
- if ( mlt_properties_get_int( properties, "real_width" ) )
+ // If meta.media.width/height exist, we want that as minimum information
+ if ( mlt_properties_get_int( properties, "meta.media.width" ) )
{
- iwidth = mlt_properties_get_int( properties, "real_width" );
- iheight = mlt_properties_get_int( properties, "real_height" );
+ iwidth = mlt_properties_get_int( properties, "meta.media.width" );
+ iheight = mlt_properties_get_int( properties, "meta.media.height" );
}
// Let the producer know what we are actually requested to obtain
*format = mlt_image_yuv422;
// Get the image as requested
- mlt_frame_get_image( this, image, format, &iwidth, &iheight, writable );
+ mlt_frame_get_image( frame, image, format, &iwidth, &iheight, writable );
// Get rescale interpretation again, in case the producer wishes to override scaling
interps = mlt_properties_get( properties, "rescale.interp" );
if ( *image && strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
{
- mlt_log_debug( MLT_FILTER_SERVICE( filter ), "%dx%d -> %dx%d (%s)\n",
- iwidth, iheight, owidth, oheight, mlt_image_format_name( *format ) );
+ mlt_log_debug( MLT_FILTER_SERVICE( filter ), "%dx%d -> %dx%d (%s) %s\n",
+ iwidth, iheight, owidth, oheight, mlt_image_format_name( *format ), interps );
// If valid colorspace
if ( *format == mlt_image_yuv422 || *format == mlt_image_rgb24 ||
*format == mlt_image_rgb24a || *format == mlt_image_opengl )
{
// Call the virtual function
- scaler_method( this, image, format, iwidth, iheight, owidth, oheight );
+ scaler_method( frame, image, format, iwidth, iheight, owidth, oheight );
*width = owidth;
*height = oheight;
}
int alpha_size = 0;
mlt_properties_get_data( properties, "alpha", &alpha_size );
if ( alpha_size > 0 && alpha_size != ( owidth * oheight ) && alpha_size != ( owidth * ( oheight + 1 ) ) )
- scale_alpha( this, iwidth, iheight, owidth, oheight );
+ scale_alpha( frame, iwidth, iheight, owidth, oheight );
}
else
{
}
else
{
- // Store the requested width/height
- int iwidth = *width;
- int iheight = *height;
-
- // Get the image as requested
- mlt_frame_get_image( this, image, format, &iwidth, &iheight, writable );
-
- // Too small - for now just assign as though we got what we wanted
- *width = iwidth;
- *height = iheight;
+ error = 1;
}
-
- return 0;
+ return error;
}
/** Filter processing.
*/
-static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
{
// Push the filter
- mlt_frame_push_service( frame, this );
+ mlt_frame_push_service( frame, filter );
// Push the get image method
mlt_frame_push_service( frame, filter_get_image );
mlt_filter filter_rescale_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
{
// Create a new scaler
- mlt_filter this = mlt_filter_new( );
+ mlt_filter filter = mlt_filter_new( );
// If successful, then initialise it
- if ( this != NULL )
+ if ( filter != NULL )
{
// Get the properties
- mlt_properties properties = MLT_FILTER_PROPERTIES( this );
+ mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
// Set the process method
- this->process = filter_process;
+ filter->process = filter_process;
// Set the inerpolation
mlt_properties_set( properties, "interpolation", arg == NULL ? "bilinear" : arg );
mlt_properties_set_data( properties, "method", filter_scale, 0, NULL, NULL );
}
- return this;
+ return filter;
}