X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodules%2Fcore%2Ffilter_imageconvert.c;h=33c938802ce8762a91d1d840e24c09982cdcf8b8;hb=c27fb53aea55a3ef8c52726e4f7f03b7ac768769;hp=d6cb3dc1cc875b81dd9d394c32c76dce10fefdac;hpb=1ccbb7551d5e42252950ee5916a69d8c80bf1b1d;p=mlt diff --git a/src/modules/core/filter_imageconvert.c b/src/modules/core/filter_imageconvert.c index d6cb3dc1..33c93880 100644 --- a/src/modules/core/filter_imageconvert.c +++ b/src/modules/core/filter_imageconvert.c @@ -55,6 +55,14 @@ g = g < 0 ? 0 : g > 255 ? 255 : g; \ b = b < 0 ? 0 : b > 255 ? 255 : b; +#define SCALED 1 +#if SCALED +#define RGB2YUV_601 RGB2YUV_601_SCALED +#define YUV2RGB_601 YUV2RGB_601_SCALED +#else +#define RGB2YUV_601 RGB2YUV_601_UNSCALED +#define YUV2RGB_601 YUV2RGB_601_UNSCALED +#endif static int convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, uint8_t *alpha, int width, int height ) { @@ -68,17 +76,17 @@ static int convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, uint8_t *alpha yy = yuv[0]; uu = yuv[1]; vv = yuv[3]; - YUV2RGB_601_SCALED (yy, uu, vv, r, g, b); + YUV2RGB_601( yy, uu, vv, r, g, b ); rgba[0] = r; rgba[1] = g; rgba[2] = b; - rgba[3] = 255; + rgba[3] = *alpha++; yy = yuv[2]; - YUV2RGB_601_SCALED (yy, uu, vv, r, g, b); + 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; } @@ -97,12 +105,12 @@ static int convert_yuv422_to_rgb24( uint8_t *yuv, uint8_t *rgb, uint8_t *alpha, yy = yuv[0]; uu = yuv[1]; vv = yuv[3]; - YUV2RGB_601_SCALED (yy, uu, vv, r, g, b); + YUV2RGB_601( yy, uu, vv, r, g, b ); rgb[0] = r; rgb[1] = g; rgb[2] = b; yy = yuv[2]; - YUV2RGB_601_SCALED (yy, uu, vv, r, g, b); + YUV2RGB_601( yy, uu, vv, r, g, b ); rgb[3] = r; rgb[4] = g; rgb[5] = b; @@ -132,12 +140,12 @@ static int convert_rgb24a_to_yuv422( uint8_t *rgba, uint8_t *yuv, uint8_t *alpha g = *s++; b = *s++; *alpha++ = *s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); r = *s++; g = *s++; b = *s++; *alpha++ = *s++; - RGB2YUV_601_SCALED (r, g, b, y1, u1 , v1); + RGB2YUV_601( r, g, b, y1, u1 , v1 ); *d++ = y0; *d++ = (u0+u1) >> 1; *d++ = y1; @@ -149,7 +157,7 @@ static int convert_rgb24a_to_yuv422( uint8_t *rgba, uint8_t *yuv, uint8_t *alpha g = *s++; b = *s++; *alpha++ = *s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); *d++ = y0; *d++ = u0; } @@ -165,12 +173,12 @@ static int convert_rgb24a_to_yuv422( uint8_t *rgba, uint8_t *yuv, uint8_t *alpha g = *s++; b = *s++; s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); r = *s++; g = *s++; b = *s++; s++; - RGB2YUV_601_SCALED (r, g, b, y1, u1 , v1); + RGB2YUV_601( r, g, b, y1, u1 , v1 ); *d++ = y0; *d++ = (u0+u1) >> 1; *d++ = y1; @@ -182,7 +190,7 @@ static int convert_rgb24a_to_yuv422( uint8_t *rgba, uint8_t *yuv, uint8_t *alpha g = *s++; b = *s++; s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); *d++ = y0; *d++ = u0; } @@ -209,11 +217,11 @@ static int convert_rgb24_to_yuv422( uint8_t *rgb, uint8_t *yuv, uint8_t *alpha, r = *s++; g = *s++; b = *s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); r = *s++; g = *s++; b = *s++; - RGB2YUV_601_SCALED (r, g, b, y1, u1 , v1); + RGB2YUV_601( r, g, b, y1, u1 , v1 ); *d++ = y0; *d++ = (u0+u1) >> 1; *d++ = y1; @@ -224,7 +232,7 @@ static int convert_rgb24_to_yuv422( uint8_t *rgb, uint8_t *yuv, uint8_t *alpha, r = *s++; g = *s++; b = *s++; - RGB2YUV_601_SCALED (r, g, b, y0, u0 , v0); + RGB2YUV_601( r, g, b, y0, u0 , v0 ); *d++ = y0; *d++ = u0; } @@ -316,21 +324,30 @@ static int convert_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *f { conversion_function converter = conversion_matrix[ *format - 1 ][ requested_format - 1 ]; - mlt_log_debug( NULL, "[filter imageconvert] %s -> %s\n", - mlt_image_format_name( *format ), mlt_image_format_name( requested_format ) ); + mlt_log_debug( NULL, "[filter imageconvert] %s -> %s @ %dx%d\n", + mlt_image_format_name( *format ), mlt_image_format_name( requested_format ), + width, height ); if ( converter ) { int size = width * height * bpp_table[ requested_format - 1 ]; + int alpha_size = width * height; uint8_t *image = mlt_pool_alloc( size ); 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 ) + { + if ( alpha ) + mlt_pool_release( alpha ); + alpha = mlt_frame_get_alpha_mask( frame ); + mlt_properties_get_data( properties, "alpha", &alpha_size ); + } if ( !( error = converter( *buffer, image, alpha, width, height ) ) ) { - mlt_properties_set_data( properties, "image", image, size, mlt_pool_release, NULL ); - if ( alpha ) - mlt_properties_set_data( properties, "alpha", alpha, width * height, mlt_pool_release, NULL ); + mlt_frame_set_image( frame, image, size, mlt_pool_release ); + if ( alpha && ( *format == mlt_image_rgb24a || *format == mlt_image_opengl ) ) + mlt_frame_set_alpha( frame, alpha, alpha_size, mlt_pool_release ); *buffer = image; *format = requested_format; } @@ -346,8 +363,6 @@ static int convert_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *f error = 1; } } - if ( !error ) - mlt_properties_set_int( properties, "format", *format ); return error; } @@ -357,7 +372,8 @@ static int convert_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *f static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) { - frame->convert_image = convert_image; + if ( !frame->convert_image ) + frame->convert_image = convert_image; return frame; } @@ -366,7 +382,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_filter filter_imageconvert_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { - mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); + mlt_filter this = calloc( 1, sizeof( struct mlt_filter_s ) ); if ( mlt_filter_init( this, this ) == 0 ) { this->process = filter_process;