]> git.sesse.net Git - mlt/commitdiff
fix crash when switching image formats with alpha
authorDan Dennedy <dan@dennedy.org>
Tue, 24 Jul 2012 06:12:04 +0000 (23:12 -0700)
committerDan Dennedy <dan@dennedy.org>
Tue, 24 Jul 2012 06:12:04 +0000 (23:12 -0700)
This happens when switching from image format with distinct alpha
channel (yuv422) to one with embedded alpha channel (rgb24a).

Reported-by: j-b-m
src/modules/gtk2/producer_pixbuf.c
src/modules/qimage/qimage_wrapper.cpp

index 0aa2a683d2f1c83b65c704eb2e5a1483c1a4dd5d..48d2032e607c023f4217b6df63bbe5c8da0f9023 100644 (file)
@@ -438,6 +438,7 @@ static void refresh_image( producer_pixbuf self, mlt_frame frame, mlt_image_form
                int dst_stride = self->width * ( has_alpha ? 4 : 3 );
                int image_size = dst_stride * ( height + 1 );
                self->image = mlt_pool_alloc( image_size );
+               self->alpha = NULL;
                self->format = has_alpha ? mlt_image_rgb24a : mlt_image_rgb24;
 
                if ( src_stride != dst_stride )
@@ -485,13 +486,18 @@ static void refresh_image( producer_pixbuf self, mlt_frame frame, mlt_image_form
                        }
                }
 
+               // Update the cache
                mlt_cache_item_close( self->image_cache );
                mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.image", self->image, image_size, mlt_pool_release );
                self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.image" );
                self->image_idx = current_idx;
                mlt_cache_item_close( self->alpha_cache );
-               mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha", self->alpha, width * height, mlt_pool_release );
-               self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha" );
+               self->alpha_cache = NULL;
+               if ( self->alpha )
+               {
+                       mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha", self->alpha, width * height, mlt_pool_release );
+                       self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha" );
+               }
 
                // Finished with pixbuf now
                g_object_unref( pixbuf );
index e7daef239a4808034b8c2c1fa73ad01395621edc..3c866d1e2fb37ed17afc02ea1f05fd7e6dbd4740 100644 (file)
@@ -268,6 +268,7 @@ void refresh_image( producer_qimage self, mlt_frame frame, mlt_image_format form
                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->current_alpha = NULL;
                self->format = has_alpha ? mlt_image_rgb24a : mlt_image_rgb24;
 
                // Copy the image
@@ -320,8 +321,12 @@ void refresh_image( producer_qimage self, mlt_frame frame, mlt_image_format form
                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 ), "qimage.alpha", self->current_alpha, width * height, mlt_pool_release );
-               self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.alpha" );
+               self->alpha_cache = NULL;
+               if ( self->current_alpha )
+               {
+                       mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "qimage.alpha", self->current_alpha, width * height, mlt_pool_release );
+                       self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "qimage.alpha" );
+               }
        }
 
        // Set width/height of frame