]> git.sesse.net Git - mlt/commitdiff
apply patch from Jean Baptiste to add rgb24a support to producer_pixbuf
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 22 May 2006 00:59:48 +0000 (00:59 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 22 May 2006 00:59:48 +0000 (00:59 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@912 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_frame.c
src/framework/mlt_frame.h
src/modules/gtk2/producer_pixbuf.c

index e17898431078191827e385eddd4a09c961ba3d71..9c6922b19f3c3ba1388c8dbb11aaa6320017a2ad 100644 (file)
@@ -529,6 +529,41 @@ void mlt_frame_close( mlt_frame this )
 
 /***** convenience functions *****/
 
+int mlt_convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, unsigned int total )
+{
+       int ret = 0;
+       int yy, uu, vv, ug_plus_vg, ub, vr;
+       int r,g,b;
+       total /= 2;
+       while (total--) 
+       {
+               yy = yuv[0] << 8;
+               uu = yuv[1] - 128;
+               vv = yuv[3] - 128;
+               ug_plus_vg = uu * 88 + vv * 183;
+               ub = uu * 454;
+               vr = vv * 359;
+               r = (yy + vr) >> 8;
+               g = (yy - ug_plus_vg) >> 8;
+               b = (yy + ub) >> 8;
+               rgba[0] = r < 0 ? 0 : (r > 255 ? 255 : (unsigned char)r);
+               rgba[1] = g < 0 ? 0 : (g > 255 ? 255 : (unsigned char)g);
+               rgba[2] = b < 0 ? 0 : (b > 255 ? 255 : (unsigned char)b);
+               rgba[3] = 255;
+               yy = yuv[2] << 8;
+               r = (yy + vr) >> 8;
+               g = (yy - ug_plus_vg) >> 8;
+               b = (yy + ub) >> 8;
+               rgba[4] = r < 0 ? 0 : (r > 255 ? 255 : (unsigned char)r);
+               rgba[5] = g < 0 ? 0 : (g > 255 ? 255 : (unsigned char)g);
+               rgba[6] = b < 0 ? 0 : (b > 255 ? 255 : (unsigned char)b);
+               rgba[7] = 255;
+               yuv += 4;
+               rgba += 8;
+       }
+       return ret;
+}
+
 int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
 {
        int ret = 0;
index bd2ea27e7b9eb4895b53e10a1c6b741904b33a2a..da61da10e7881c9e5fb77353514bf6c428e56be6 100644 (file)
@@ -74,6 +74,7 @@ extern mlt_producer mlt_frame_get_original_producer( mlt_frame self );
 extern void mlt_frame_close( mlt_frame self );
 
 /* convenience functions */
+extern int mlt_convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, unsigned int total );
 extern int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha );
 extern int mlt_convert_rgb24_to_yuv422( uint8_t *rgb, int width, int height, int stride, uint8_t *yuv );
 extern int mlt_convert_bgr24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha );
index 1217bdf434908fa8bcbfd59fa94d9e48ed89366d..dad221ce4f1a45f7e274b0d46e704bf7f625a863 100644 (file)
@@ -55,6 +55,7 @@ struct producer_pixbuf_s
 static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
 static void producer_close( mlt_producer parent );
 
+
 mlt_producer producer_pixbuf_init( char *filename )
 {
        producer_pixbuf this = calloc( sizeof( struct producer_pixbuf_s ), 1 );
@@ -241,24 +242,45 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // The fault is not in the design of mlt, but in the implementation of the pixbuf producer...
        if ( *buffer != NULL )
        {
-               // Clone the image and the alpha
-               uint8_t *image_copy = mlt_pool_alloc( image_size );
-               uint8_t *alpha_copy = mlt_pool_alloc( alpha_size );
 
-               memcpy( image_copy, *buffer, image_size );
+               if ( *format == mlt_image_yuv422 || *format == mlt_image_yuv420p )
+               {
+                       // Clone the image and the alpha
+                       uint8_t *image_copy = mlt_pool_alloc( image_size );
+                       uint8_t *alpha_copy = mlt_pool_alloc( alpha_size );
 
-               // Copy or default the alpha
-               if ( alpha != NULL )
-                       memcpy( alpha_copy, alpha, alpha_size );
-               else
-                       memset( alpha_copy, 255, alpha_size );
+                       memcpy( image_copy, *buffer, image_size );
 
-               // Now update properties so we free the copy after
-               mlt_properties_set_data( properties, "image", image_copy, image_size, mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "alpha", alpha_copy, alpha_size, mlt_pool_release, NULL );
+                       // Copy or default the alpha
+                       if ( alpha != NULL )
+                               memcpy( alpha_copy, alpha, alpha_size );
+                       else
+                               memset( alpha_copy, 255, alpha_size );
 
-               // We're going to pass the copy on
-               *buffer = image_copy;
+                       // Now update properties so we free the copy after
+                       mlt_properties_set_data( properties, "image", image_copy, image_size, mlt_pool_release, NULL );
+                       mlt_properties_set_data( properties, "alpha", alpha_copy, alpha_size, mlt_pool_release, NULL );
+
+                       // We're going to pass the copy on
+                       *buffer = image_copy;
+               }
+               else if ( *format == mlt_image_rgb24a )
+               {
+                       // Clone the image and the alpha
+                       image_size = *width * ( *height + 1 ) * 4;
+                       alpha_size = *width * ( *height + 1 );
+                       uint8_t *image_copy = mlt_pool_alloc( image_size );
+                       uint8_t *alpha_copy = mlt_pool_alloc( alpha_size );
+
+                       mlt_convert_yuv422_to_rgb24a(*buffer, image_copy, (*width)*(*height));
+
+                       // Now update properties so we free the copy after
+                       mlt_properties_set_data( properties, "image", image_copy, image_size, mlt_pool_release, NULL );
+                       mlt_properties_set_data( properties, "alpha", alpha_copy, alpha_size, mlt_pool_release, NULL );
+
+                       // We're going to pass the copy on
+                       *buffer = image_copy;
+               }
        }
        else
        {
@@ -272,6 +294,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        return 0;
 }
 
+
 static uint8_t *producer_get_alpha_mask( mlt_frame this )
 {
        // Obtain properties of frame