]> git.sesse.net Git - mlt/commitdiff
Apply alpha on frame to rgba image (kdenlive-1786).
authorDan Dennedy <dan@dennedy.org>
Mon, 6 Sep 2010 06:35:48 +0000 (23:35 -0700)
committerDan Dennedy <dan@dennedy.org>
Mon, 6 Sep 2010 06:35:48 +0000 (23:35 -0700)
src/modules/avformat/filter_avcolour_space.c
src/modules/core/filter_imageconvert.c

index e606d802fd52b2161b89b9fdd87e8947d00be91a..6216d8cec74ab668d1e20c46e7bb85af6c16014c 100644 (file)
@@ -167,6 +167,34 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
                *format = output_format;
                mlt_properties_set_data( properties, "image", output, size, mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "format", output_format );
+
+               if ( output_format == mlt_image_rgb24a || output_format == mlt_image_opengl )
+               {
+                       register int len = width * height;
+                       uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
+
+                       if ( alpha )
+                       {
+                               // Merge the alpha mask from into the RGBA image using Duff's Device
+                               register uint8_t *s = alpha;
+                               register uint8_t *d = *image + 3; // start on the alpha component
+                               register int n = ( len + 7 ) / 8;
+
+                               switch ( len % 8 )
+                               {
+                                       case 0: do { *d = *s++; d += 4;
+                                       case 7:          *d = *s++; d += 4;
+                                       case 6:          *d = *s++; d += 4;
+                                       case 5:          *d = *s++; d += 4;
+                                       case 4:          *d = *s++; d += 4;
+                                       case 3:          *d = *s++; d += 4;
+                                       case 2:          *d = *s++; d += 4;
+                                       case 1:          *d = *s++; d += 4;
+                                                       }
+                                                       while ( --n > 0 );
+                               }
+                       }
+               }
        }
        return error;
 }
index aa2e024b402a972f864c62ac28bec8596f02aca4..41567235bd0d743163dcd3134013de0930bbc6aa 100644 (file)
@@ -80,13 +80,13 @@ static int convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, uint8_t *alpha
                rgba[0] = r;
                rgba[1] = g;
                rgba[2] = b;
-               rgba[3] = 255;
+               rgba[3] = *alpha++;
                yy = yuv[2];
                YUV2RGB_601( yy, uu, vv, r, g, b );
                rgba[4] = r;
                rgba[5] = g;
                rgba[6] = b;
-               rgba[7] = 255;
+               rgba[7] = *alpha++;
                yuv += 4;
                rgba += 8;
        }
@@ -333,11 +333,13 @@ static int convert_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *f
                        uint8_t *alpha = ( *format == mlt_image_rgb24a ||
                                           *format == mlt_image_opengl )
                                         ? mlt_pool_alloc( width * height ) : NULL;
+                       if ( requested_format == mlt_image_rgb24a || requested_format == mlt_image_opengl )
+                               alpha = mlt_frame_get_alpha_mask( frame );
 
                        if ( !( error = converter( *buffer, image, alpha, width, height ) ) )
                        {
                                mlt_properties_set_data( properties, "image", image, size, mlt_pool_release, NULL );
-                               if ( alpha )
+                               if ( alpha && ( *format == mlt_image_rgb24a || *format == mlt_image_opengl ) )
                                        mlt_properties_set_data( properties, "alpha", alpha, width * height, mlt_pool_release, NULL );
                                *buffer = image;
                                *format = requested_format;