// Determine the bytes per pixel
int bpp;
+ mlt_image_format_size( *format, 0, 0, &bpp );
+
+ // Set swscale flags to get good quality
switch ( *format )
{
case mlt_image_yuv422:
- bpp = 2;
interp |= SWS_FULL_CHR_H_INP;
break;
case mlt_image_rgb24:
- bpp = 3;
interp |= SWS_FULL_CHR_H_INT;
break;
case mlt_image_rgb24a:
case mlt_image_opengl:
- bpp = 4;
interp |= SWS_FULL_CHR_H_INT;
break;
default:
if ( codec_context->pix_fmt == PIX_FMT_RGB32 )
size = *width * ( *height + 1 ) * 4;
- else switch ( *format )
- {
- case mlt_image_yuv420p:
- size = *width * 3 * ( *height + 1 ) / 2;
- break;
- case mlt_image_rgb24:
- size = *width * ( *height + 1 ) * 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- size = *width * ( *height + 1 ) * 4;
- break;
- default:
- *format = mlt_image_yuv422;
- size = *width * ( *height + 1 ) * 2;
- break;
- }
+ else
+ size = mlt_image_format_size( *format, *width, *height, NULL );
// Construct the output image
*buffer = mlt_pool_alloc( size );
*height = 1080;
// Cache hit
- int size;
- switch ( *format )
- {
- case mlt_image_yuv420p:
- size = *width * 3 * ( *height + 1 ) / 2;
- break;
- case mlt_image_rgb24:
- size = *width * ( *height + 1 ) * 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- size = *width * ( *height + 1 ) * 4;
- break;
- default:
- *format = mlt_image_yuv422;
- size = *width * ( *height + 1 ) * 2;
- break;
- }
+ int size = mlt_image_format_size( *format, *width, *height, NULL );
mlt_properties_set_data( frame_properties, "avformat.image_cache", item, 0, ( mlt_destructor )mlt_cache_item_close, NULL );
mlt_frame_set_image( frame, *buffer, size, NULL );
// self->top_field_first = mlt_properties_get_int( frame_properties, "top_field_first" );
// Now handle the picture if we have one
if ( got_picture )
{
- if ( ( image_size = allocate_buffer( frame_properties, codec_context, buffer, format, width, height ) ) )
+ if ( ( image_size = allocate_buffer( frame, codec_context, buffer, format, width, height ) ) )
{
// Workaround 1088 encodings missing cropping info.
if ( *height == 1088 && mlt_profile_dar( mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ) ) == 16.0/9.0 )
mlt_log_debug( NULL, "[filter crop] %s %dx%d -> %dx%d\n", mlt_image_format_name(*format),
*width, *height, owidth, oheight);
- switch ( *format )
- {
- case mlt_image_yuv422:
- bpp = 2;
- break;
- case mlt_image_rgb24:
- bpp = 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- bpp = 4;
- break;
- default:
- // XXX: we only know how to crop packed formats
- return 1;
- }
// Provides a manual override for misreported field order
if ( mlt_properties_get( properties, "meta.top_field_first" ) )
mlt_properties_set_int( properties, "top_field_first", !mlt_properties_get_int( properties, "top_field_first" ) );
// Create the output image
- uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * bpp );
+ int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
+ uint8_t *output = mlt_pool_alloc( size );
if ( output )
{
// Call the generic resize
crop( *image, output, bpp, *width, *height, left, right, top, bottom );
// Now update the frame
- mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
+ mlt_frame_set_image( this, output, size, mlt_pool_release );
*image = output;
}
// Get the requested scale operation
char *op = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "scale" );
int bpp;
-
- switch ( *format )
- {
- case mlt_image_yuv422:
- bpp = 2;
- break;
- case mlt_image_rgb24:
- bpp = 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- bpp = 4;
- break;
- default:
- // XXX: we only know how to resize packed formats
- return 1;
- }
+ int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
// Provides a manual override for misreported field order
if ( mlt_properties_get( properties, "meta.top_field_first" ) )
mlt_properties_get_int( properties, "progressive" ) == 0 )
{
// Get the input image, width and height
- int size = owidth * oheight * bpp;
uint8_t *new_image = mlt_pool_alloc( size );
mlt_frame_set_image( this, new_image, size, mlt_pool_release );
uint8_t *ptr = new_image + owidth * bpp;
memcpy( new_image, *image, owidth * bpp );
- memcpy( ptr, *image, size - owidth * bpp );
+ memcpy( ptr, *image, owidth * ( oheight - 1 ) * bpp );
*image = new_image;
// Set the normalised field order
int i = *width * *height + 1;
int bpp;
- switch ( *format )
- {
- case mlt_image_rgb24:
- bpp = 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- bpp = 4;
- break;
- default:
- bpp = 2;
- *format = mlt_image_yuv422;
- break;
- }
-
// Allocate the image
- size = *width * *height * bpp;
+ size = mlt_image_format_size( *format, *width, *height, &bpp );
uint8_t *p = image = mlt_pool_alloc( size );
// Update the producer
else if ( strcmp( interps, "hyper" ) == 0 || strcmp( interps, "bicubic" ) == 0 )
interp = PIXOPS_INTERP_HYPER;
+ int bpp;
+ int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
+
// Carry out the rescaling
switch ( *format )
{
case mlt_image_yuv422:
{
// Create the output image
- uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
+ uint8_t *output = mlt_pool_alloc( size );
// Calculate strides
int istride = iwidth * 2;
yuv422_scale_simple( output, owidth, oheight, ostride, *image, iwidth, iheight, istride, interp );
// Now update the frame
- mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * 2, mlt_pool_release );
+ mlt_frame_set_image( this, output, size, mlt_pool_release );
// Return the output
*image = output;
case mlt_image_rgb24a:
case mlt_image_opengl:
{
- int bpp = ( *format == mlt_image_rgb24 ? 3 : 4 );
-
// Create the output image
- uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * bpp );
+ uint8_t *output = mlt_pool_alloc( size );
if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
{
g_object_unref( scaled );
// Now update the frame
- mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
+ mlt_frame_set_image( this, output, size, mlt_pool_release );
// Return the output
*image = output;
uint8_t *buffer = NULL;
int error = mlt_frame_get_image( freeze_frame, &buffer, format, width, height, 1 );
- int size = 0;
- switch ( *format )
- {
- case mlt_image_yuv420p:
- size = *width * 3 * ( *height + 1 ) / 2;
- break;
- case mlt_image_rgb24:
- size = *width * ( *height + 1 ) * 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- size = *width * ( *height + 1 ) * 4;
- break;
- default:
- *format = mlt_image_yuv422;
- size = *width * ( *height + 1 ) * 2;
- break;
- }
-
// Copy it to current frame
- uint8_t *image_copy = mlt_pool_alloc( size );
+ int size = mlt_image_format_size( *format, *width, *height, NULL );
+ uint8_t *image_copy = mlt_pool_alloc( size );
memcpy( image_copy, buffer, size );
*image = image_copy;
mlt_frame_set_image( this, *image, size, mlt_pool_release );
// Determine output buffer size
*width = mlt_properties_get_int( frame_properties, "width" );
*height = mlt_properties_get_int( frame_properties, "height" );
-
- int size;
- switch ( *format )
- {
- case mlt_image_yuv420p:
- size = *width * 3 * ( *height + 1 ) / 2;
- break;
- case mlt_image_rgb24:
- size = *width * ( *height + 1 ) * 3;
- break;
- case mlt_image_rgb24a:
- case mlt_image_opengl:
- size = *width * ( *height + 1 ) * 4;
- break;
- default:
- *format = mlt_image_yuv422;
- size = *width * ( *height + 1 ) * 2;
- break;
- }
-
+ int size = mlt_image_format_size( *format, *width, *height, NULL );
// Get output buffer
int buffersize = 0;