self->qimage = mlt_cache_item_data( self->qimage_cache, NULL );
self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.image" );
self->current_image = mlt_cache_item_data( self->image_cache, NULL );
- refresh_image( self, frame, *width, *height );
+ self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.alpha" );
+ self->current_alpha = mlt_cache_item_data( self->alpha_cache, NULL );
+ refresh_image( self, frame, *format, *width, *height );
// Get width and height (may have changed during the refresh)
*width = mlt_properties_get_int( properties, "width" );
*height = mlt_properties_get_int( properties, "height" );
- *format = self->has_alpha ? mlt_image_rgb24a : mlt_image_rgb24;
+ *format = self->format;
// NB: Cloning is necessary with this producer (due to processing of images ahead of use)
// The fault is not in the design of mlt, but in the implementation of the qimage producer...
if ( self->current_image )
{
// Clone the image and the alpha
- int image_size = self->current_width * ( self->current_height + 1 ) * ( self->has_alpha ? 4 :3 );
+ int image_size = mlt_image_format_size( self->format, self->current_width, self->current_height, NULL );
uint8_t *image_copy = mlt_pool_alloc( image_size );
memcpy( image_copy, self->current_image, image_size );
// Now update properties so we free the copy after
*buffer = image_copy;
mlt_log_debug( MLT_PRODUCER_SERVICE( &self->parent ), "%dx%d (%s)\n",
self->current_width, self->current_height, mlt_image_format_name( *format ) );
+ // Clone the alpha channel
+ if ( self->current_alpha )
+ {
+ image_copy = mlt_pool_alloc( self->current_width * self->current_height );
+ memcpy( image_copy, self->current_alpha, self->current_width * self->current_height );
+ mlt_frame_set_alpha( frame, image_copy, self->current_width * self->current_height, mlt_pool_release );
+ }
}
else
{
// Release references and locks
mlt_cache_item_close( self->qimage_cache );
mlt_cache_item_close( self->image_cache );
+ mlt_cache_item_close( self->alpha_cache );
mlt_service_unlock( MLT_PRODUCER_SERVICE( &self->parent ) );
return error;
return image_idx;
}
-void refresh_image( producer_qimage self, mlt_frame frame, int width, int height )
+void refresh_image( producer_qimage self, mlt_frame frame, mlt_image_format format, int width, int height )
{
// Obtain properties of frame and producer
mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
self->current_image = NULL;
// If we have a qimage and need a new scaled image
- if ( self->qimage && !self->current_image )
+ if ( self->qimage && ( !self->current_image || ( format != mlt_image_none && format != self->format ) ) )
{
char *interps = mlt_properties_get( properties, "rescale.interp" );
int interp = 0;
}
QImage scaled = interp == 0 ? qimage->scaled( QSize( width, height ) ) :
qimage->scaled( QSize(width, height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
- self->has_alpha = scaled.hasAlphaChannel();
+ int has_alpha = scaled.hasAlphaChannel();
#endif
#ifdef USE_QT3
self->current_height = height;
// Allocate/define image
- int dst_stride = width * ( self->has_alpha ? 4 : 3 );
+ int dst_stride = width * ( has_alpha ? 4 : 3 );
int image_size = dst_stride * ( height + 1 );
self->current_image = ( uint8_t * )mlt_pool_alloc( image_size );
+ self->format = has_alpha ? mlt_image_rgb24a : mlt_image_rgb24;
// Copy the image
int y = self->current_height + 1;
*dst++ = qRed(*src);
*dst++ = qGreen(*src);
*dst++ = qBlue(*src);
- if ( self->has_alpha ) *dst++ = qAlpha(*src);
+ if ( has_alpha ) *dst++ = qAlpha(*src);
++src;
}
}
+ // 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_set_image( frame, self->current_image, image_size, mlt_pool_release );
+ mlt_properties_set_int( properties, "format", self->format );
+ mlt_properties_set_int( properties, "width", width );
+ mlt_properties_set_int( properties, "height", height );
+ 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 );
+ }
+ }
+
// Update the cache
mlt_cache_item_close( self->image_cache );
mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "qimage.image", self->current_image, image_size, mlt_pool_release );
self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.image" );
self->image_idx = image_idx;
+ mlt_cache_item_close( self->alpha_cache );
+ mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha", self->current_alpha, width * height, mlt_pool_release );
+ self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha" );
}
// Set width/height of frame
int image_idx;
int qimage_idx;
uint8_t *current_image;
- int has_alpha;
+ uint8_t *current_alpha;
int current_width;
int current_height;
mlt_cache_item image_cache;
+ mlt_cache_item alpha_cache;
mlt_cache_item qimage_cache;
void *qimage;
+ mlt_image_format format;
};
typedef struct producer_qimage_s *producer_qimage;
extern int refresh_qimage( producer_qimage self, mlt_frame frame );
-extern void refresh_image( producer_qimage, mlt_frame, int width, int height );
+extern void refresh_image( producer_qimage, mlt_frame, mlt_image_format, int width, int height );
extern void make_tempfile( producer_qimage, const char *xml );
#ifdef USE_KDE