From: ddennedy Date: Mon, 22 May 2006 00:59:48 +0000 (+0000) Subject: apply patch from Jean Baptiste to add rgb24a support to producer_pixbuf X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=05b29b78bfb59b49836719573f4c7503066bad04;p=melted apply patch from Jean Baptiste to add rgb24a support to producer_pixbuf git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@912 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index e178984..9c6922b 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -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; diff --git a/src/framework/mlt_frame.h b/src/framework/mlt_frame.h index bd2ea27..da61da1 100644 --- a/src/framework/mlt_frame.h +++ b/src/framework/mlt_frame.h @@ -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 ); diff --git a/src/modules/gtk2/producer_pixbuf.c b/src/modules/gtk2/producer_pixbuf.c index 1217bdf..dad221c 100644 --- a/src/modules/gtk2/producer_pixbuf.c +++ b/src/modules/gtk2/producer_pixbuf.c @@ -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