#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
/** Constructor for a frame.
*/
/***** convenience functions *****/
+int mlt_convert_yuv422_to_rgb24a( uint8_t *yuv, uint8_t *rgba, unsigned int total )
+{
+ int ret = 0;
+ int yy, uu, vv;
+ int r,g,b;
+ total /= 2;
+ while (total--)
+ {
+ yy = yuv[0];
+ uu = yuv[1];
+ vv = yuv[3];
+ YUV2RGB(yy, uu, vv, r, g, b);
+ rgba[0] = r;
+ rgba[1] = g;
+ rgba[2] = b;
+ rgba[3] = 255;
+ yy = yuv[2];
+ YUV2RGB(yy, uu, vv, r, g, b);
+ rgba[4] = r;
+ rgba[5] = g;
+ rgba[6] = 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;
return ret;
}
+int mlt_convert_bgr24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
+{
+ int ret = 0;
+ register int y0, y1, u0, u1, v0, v1;
+ register int r, g, b;
+ register uint8_t *d = yuv;
+ register int i, j;
+
+ for ( i = 0; i < height; i++ )
+ {
+ register uint8_t *s = rgba + ( stride * i );
+ for ( j = 0; j < ( width / 2 ); j++ )
+ {
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ *alpha++ = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ *alpha++ = *s++;
+ RGB2YUV (r, g, b, y1, u1 , v1);
+ *d++ = y0;
+ *d++ = (u0+u1) >> 1;
+ *d++ = y1;
+ *d++ = (v0+v1) >> 1;
+ }
+ if ( width % 2 )
+ {
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ *alpha++ = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ *d++ = y0;
+ *d++ = u0;
+ }
+ }
+ return ret;
+}
+
+int mlt_convert_bgr24_to_yuv422( uint8_t *rgb, int width, int height, int stride, uint8_t *yuv )
+{
+ int ret = 0;
+ register int y0, y1, u0, u1, v0, v1;
+ register int r, g, b;
+ register uint8_t *d = yuv;
+ register int i, j;
+
+ for ( i = 0; i < height; i++ )
+ {
+ register uint8_t *s = rgb + ( stride * i );
+ for ( j = 0; j < ( width / 2 ); j++ )
+ {
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ RGB2YUV (r, g, b, y1, u1 , v1);
+ *d++ = y0;
+ *d++ = (u0+u1) >> 1;
+ *d++ = y1;
+ *d++ = (v0+v1) >> 1;
+ }
+ if ( width % 2 )
+ {
+ b = *s++;
+ g = *s++;
+ r = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ *d++ = y0;
+ *d++ = u0;
+ }
+ }
+ return ret;
+}
+
+int mlt_convert_argb_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
+{
+ int ret = 0;
+ register int y0, y1, u0, u1, v0, v1;
+ register int r, g, b;
+ register uint8_t *d = yuv;
+ register int i, j;
+
+ for ( i = 0; i < height; i++ )
+ {
+ register uint8_t *s = rgba + ( stride * i );
+ for ( j = 0; j < ( width / 2 ); j++ )
+ {
+ *alpha++ = *s++;
+ r = *s++;
+ g = *s++;
+ b = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ *alpha++ = *s++;
+ r = *s++;
+ g = *s++;
+ b = *s++;
+ RGB2YUV (r, g, b, y1, u1 , v1);
+ *d++ = y0;
+ *d++ = (u0+u1) >> 1;
+ *d++ = y1;
+ *d++ = (v0+v1) >> 1;
+ }
+ if ( width % 2 )
+ {
+ *alpha++ = *s++;
+ r = *s++;
+ g = *s++;
+ b = *s++;
+ RGB2YUV (r, g, b, y0, u0 , v0);
+ *d++ = y0;
+ *d++ = u0;
+ }
+ }
+ return ret;
+}
+
int mlt_convert_yuv420p_to_yuv422( uint8_t *yuv420p, int width, int height, int stride, uint8_t *yuv )
{
int ret = 0;
return ret;
}
-uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight )
+uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight, uint8_t alpha_value )
{
uint8_t *output = NULL;
int iused = iwidth;
output = mlt_pool_alloc( owidth * oheight );
- memset( output, 0, owidth * oheight );
+ memset( output, alpha_value, owidth * oheight );
offset_x -= offset_x % 2;
// If width and height are correct, don't do anything
if ( iwidth != owidth || iheight != oheight )
{
+ uint8_t alpha_value = mlt_properties_get_int( properties, "resize_alpha" );
+
// Create the output image
uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
mlt_properties_set_int( properties, "height", oheight );
// We should resize the alpha too
- alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight );
+ alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight, alpha_value );
if ( alpha != NULL )
{
mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL );
float weight = weight_start;
float weight_step = ( weight_end - weight_start ) / *samples;
+ if ( src == dest )
+ {
+ *samples = samples_src;
+ *channels = channels_src;
+ *buffer = src;
+ *frequency = frequency_src;
+ return ret;
+ }
+
// Mixdown
for ( i = 0; i < *samples; i++ )
{
return ret;
}
+// Replacement for broken mlt_frame_audio_mix - this filter uses an inline low pass filter
+// to allow mixing without volume hacking
+int mlt_frame_combine_audio( mlt_frame this, mlt_frame that, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
+{
+ int ret = 0;
+ int16_t *src, *dest;
+ int frequency_src = *frequency, frequency_dest = *frequency;
+ int channels_src = *channels, channels_dest = *channels;
+ int samples_src = *samples, samples_dest = *samples;
+ int i, j;
+ double vp[ 6 ];
+ double b_weight = 1.0;
+
+ if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "meta.mixdown" ) )
+ b_weight = 1.0 - mlt_properties_get_double( MLT_FRAME_PROPERTIES( this ), "meta.volume" );
+
+ mlt_frame_get_audio( that, &src, format, &frequency_src, &channels_src, &samples_src );
+ mlt_frame_get_audio( this, &dest, format, &frequency_dest, &channels_dest, &samples_dest );
+
+ int silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "silent_audio" );
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "silent_audio", 0 );
+ if ( silent )
+ memset( dest, 0, samples_dest * channels_dest * sizeof( int16_t ) );
+
+ silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( that ), "silent_audio" );
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( that ), "silent_audio", 0 );
+ if ( silent )
+ memset( src, 0, samples_src * channels_src * sizeof( int16_t ) );
+
+ if ( src == dest )
+ {
+ *samples = samples_src;
+ *channels = channels_src;
+ *buffer = src;
+ *frequency = frequency_src;
+ return ret;
+ }
+
+ // determine number of samples to process
+ *samples = samples_src < samples_dest ? samples_src : samples_dest;
+ *channels = channels_src < channels_dest ? channels_src : channels_dest;
+ *buffer = dest;
+ *frequency = frequency_dest;
+
+ for ( j = 0; j < *channels; j++ )
+ vp[ j ] = ( double )dest[ j ];
+
+ double Fc = 0.5;
+ double B = exp(-2.0 * M_PI * Fc);
+ double A = 1.0 - B;
+ double v;
+
+ for ( i = 0; i < *samples; i++ )
+ {
+ for ( j = 0; j < *channels; j++ )
+ {
+ v = ( double )( b_weight * dest[ i * channels_dest + j ] + src[ i * channels_src + j ] );
+ v = v < -32767 ? -32767 : v > 32768 ? 32768 : v;
+ vp[ j ] = dest[ i * channels_dest + j ] = ( int16_t )( v * A + vp[ j ] * B );
+ }
+ }
+
+ return ret;
+}
+
/* Will this break when mlt_position is converted to double? -Zach */
int mlt_sample_calculator( float fps, int frequency, int64_t position )
{