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 )
{
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;
}
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;
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;
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;
}
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;
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;
}
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;
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;
}
{
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;
}
error = 1;
}
}
- if ( !error )
- mlt_properties_set_int( properties, "format", *format );
return error;
}
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;
}
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;