+ // Convert image to requested format
+ if ( format != mlt_image_none && format != self->format )
+ {
+ uint8_t *buffer = NULL;
+
+ // First, set the image so it can be converted when we get it
+ mlt_frame_replace_image( frame, self->current_image, self->format, width, height );
+ mlt_frame_set_image( frame, self->current_image, image_size, mlt_pool_release );
+ self->format = format;
+
+ // get_image will do the format conversion
+ mlt_frame_get_image( frame, &buffer, &format, &width, &height, 0 );
+
+ // cache copies of the image and alpha buffers
+ if ( buffer )
+ {
+ image_size = mlt_image_format_size( format, width, height, NULL );
+ self->current_image = (uint8_t*) mlt_pool_alloc( image_size );
+ memcpy( self->current_image, buffer, image_size );
+ }
+ if ( ( buffer = mlt_frame_get_alpha_mask( frame ) ) )
+ {
+ self->current_alpha = (uint8_t*) mlt_pool_alloc( width * height );
+ memcpy( self->current_alpha, buffer, width * height );
+ }
+ }
+