Skip to content

Commit

Permalink
src/framework/mlt_frame.c
Browse files Browse the repository at this point in the history
+ Corrections for resizing images and alpha (uneven widths)

src/framework/mlt_tractor.c
+ Added an output aspect ratio (being the aspect ratio of the background)

src/modules/core/filter_rescale.c
+ Force a rescale of the alpha in parallel with image

src/modules/core/filter_resize.c
+ Rounding errors corrections

src/modules/core/filter_watermark.c
+ Propogation of output aspect ratio in reverse case

src/modules/core/producer_colour.c
+ Reassign aspect ratio after get_image

src/modules/core/transition_composite.c
+ More uneven width corrections
+ Use of output aspect ratio when available

src/modules/feeds/PAL/etv.properties
+ Temporary work around to keep composites correct


git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@833 d19143bc-622f-0410-bfdd-b5b2a6649095
  • Loading branch information
lilo_booter committed Sep 28, 2005
1 parent 95f2d83 commit c974f8e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 155 deletions.
43 changes: 25 additions & 18 deletions src/framework/mlt_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for
if ( mlt_properties_get( properties, "meta.volume" ) )
{
double value = mlt_properties_get_double( properties, "meta.volume" );

if ( value == 0.0 )
{
memset( *buffer, 0, *samples * *channels * 2 );
mlt_properties_set_double( properties, "meta.volume", 1.0 );
}
else if ( value != 1.0 )
{
Expand All @@ -443,8 +443,9 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for
*p = *p * value;
p ++;
}
mlt_properties_set_double( properties, "meta.volume", 1.0 );
}

mlt_properties_set( properties, "meta.volume", NULL );
}

return 0;
Expand Down Expand Up @@ -643,23 +644,27 @@ uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth,

if ( input != NULL && ( iwidth != owidth || iheight != oheight ) && ( owidth > 6 && oheight > 6 ) )
{
uint8_t *in_line = input;
uint8_t *out_line;
int offset_x = ( owidth - iwidth ) / 2;
int offset_y = ( oheight - iheight ) / 2;
int iused = iwidth;

output = mlt_pool_alloc( owidth * oheight );
memset( output, 0, owidth * oheight );

out_line = output + ( ( oheight - iheight ) / 2 ) * owidth;
out_line += 2 * ( int )( ( owidth - iwidth ) / 2 );
offset_x -= offset_x % 2;

out_line = output + offset_y * owidth;
out_line += offset_x;

// Loop for the entirety of our output height.
while ( iheight -- )
{
// We're in the input range for this row.
memcpy( out_line, input, iwidth );
memcpy( out_line, input, iused );

// Move to next input line
in_line += iwidth;
input += iwidth;

// Move to next output line
out_line += owidth;
Expand All @@ -674,6 +679,12 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
// Calculate strides
int istride = iwidth * 2;
int ostride = owidth * 2;
int offset_x = ( owidth - iwidth );
int offset_y = ( oheight - iheight ) / 2;
uint8_t *in_line = input;
uint8_t *out_line;
int size = owidth * oheight;
uint8_t *p = output;

// Optimisation point
if ( output == NULL || input == NULL || ( owidth <= 6 || oheight <= 6 || iwidth <= 6 || oheight <= 6 ) )
Expand All @@ -686,26 +697,22 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
return;
}

uint8_t *in_line = input;
uint8_t *out_line;

int size = owidth * oheight;
uint8_t *p = output;

while( size -- )
{
*p ++ = 16;
*p ++ = 128;
}

out_line = output + ( ( oheight - iheight ) / 2 ) * ostride;
out_line += 4 * ( int )( ( owidth - iwidth ) / 4 );

offset_x -= offset_x % 4;

out_line = output + offset_y * ostride;
out_line += offset_x;

// Loop for the entirety of our output height.
while ( iheight -- )
{
// We're in the input range for this row.
memcpy( out_line, in_line, istride );
memcpy( out_line, in_line, iwidth * 2 );

// Move to next input line
in_line += istride;
Expand Down Expand Up @@ -749,7 +756,7 @@ uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight )
alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight );
if ( alpha != NULL )
{
mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL );
this->get_alpha_mask = NULL;
}

Expand Down
5 changes: 5 additions & 0 deletions src/framework/mlt_tractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra
video = temp;
if ( first_video == NULL )
first_video = temp;

// Ensure that all frames know the aspect ratio of the background
mlt_properties_set_double( temp_properties, "output_ratio",
mlt_properties_get_double( MLT_FRAME_PROPERTIES( first_video ), "aspect_ratio" ) );

mlt_properties_set_int( MLT_FRAME_PROPERTIES( temp ), "image_count", ++ image_count );
image_count = 1;
}
Expand Down
77 changes: 23 additions & 54 deletions src/modules/core/filter_rescale.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

typedef int ( *image_scaler )( mlt_frame this, uint8_t **image, mlt_image_format iformat, mlt_image_format oformat, int iwidth, int iheight, int owidth, int oheight );

Expand Down Expand Up @@ -110,60 +111,26 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format iform

static void scale_alpha( mlt_frame this, int iwidth, int iheight, int owidth, int oheight )
{
int size = 0;
uint8_t *input = mlt_properties_get_data( MLT_FRAME_PROPERTIES( this ), "alpha", &size );
if ( input != NULL && ( ( size == iwidth * iheight ) || size == ( iwidth * ( iheight + 1 ) ) ) )
uint8_t *output = NULL;
uint8_t *input = mlt_frame_get_alpha_mask( this );

if ( input != NULL )
{
uint8_t *output = mlt_pool_alloc( owidth * oheight );

// Derived coordinates
int dy, dx;

// Calculate ranges
int out_x_range = owidth / 2;
int out_y_range = oheight / 2;
int in_x_range = iwidth / 2;
int in_y_range = iheight / 2;

// Output pointers
register uint8_t *out_line = output;
register uint8_t *out_ptr;

// Calculate a middle pointer
uint8_t *in_middle = input + iwidth * in_y_range + in_x_range;
uint8_t *in_line;

// Generate the affine transform scaling values
register int scale_width = ( iwidth << 16 ) / owidth;
register int scale_height = ( iheight << 16 ) / oheight;
register int base = 0;

int outer = out_x_range * scale_width;
int bottom = out_y_range * scale_height;

// Loop for the entirety of our output height.
for ( dy = - bottom; dy < bottom; dy += scale_height )
{
// Start at the beginning of the line
out_ptr = out_line;

// Pointer to the middle of the input line
in_line = in_middle + ( dy >> 16 ) * iwidth;

// Loop for the entirety of our output row.
for ( dx = - outer; dx < outer; dx += scale_width )
{
base = dx >> 15;
*out_ptr ++ = *( in_line + base );
}

// Move to next output line
out_line += owidth;
}

this->get_alpha_mask = NULL;
mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output, 0, mlt_pool_release, NULL );
uint8_t *out_line;
int x, y;
int ox = ( iwidth << 10 ) / owidth;
int oy = ( iheight << 10 ) / oheight;

output = mlt_pool_alloc( owidth * oheight );
out_line = output;

// Loop for the entirety of our output height.
for ( y = 0; y < oheight; y ++ )
for ( x = 0; x < owidth; x ++ )
*out_line ++ = *( input + ( ( 512 + ( y * oy * iwidth ) + x * ox ) >> 10 ) );

// Set it back on the frame
mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output, owidth * oheight, mlt_pool_release, NULL );
}
}

Expand Down Expand Up @@ -224,7 +191,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
else
{
// When no scaling is requested, revert the requested dimensions if possible
mlt_properties_set_int( properties, "rescale_width", ( iwidth / 2 ) * 2 );
mlt_properties_set_int( properties, "rescale_width", iwidth );
mlt_properties_set_int( properties, "rescale_height", iheight );
}

Expand Down Expand Up @@ -285,6 +252,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
}
else
{
// Scale the alpha
scale_alpha( this, iwidth, iheight, owidth, oheight );
*width = iwidth;
*height = iheight;
}
Expand Down
9 changes: 5 additions & 4 deletions src/modules/core/filter_resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/** Do it :-).
*/
Expand Down Expand Up @@ -75,19 +76,19 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
//fprintf( stderr, "normalised %dx%d output %dx%d %f %f\n", normalised_width, normalised_height, owidth, oheight, ( float )output_ar, ( float )mlt_properties_get_double( properties, "consumer_aspect_ratio" ) * owidth / oheight );

// Optimised for the input_ar > output_ar case (e.g. widescreen on standard)
int scaled_width = ( input_ar * normalised_width ) / output_ar + 0.5;
int scaled_width = rint( 0.5 + ( input_ar * normalised_width ) / output_ar );
int scaled_height = normalised_height;

// Now ensure that our images fit in the output frame
if ( scaled_width > normalised_width )
{
scaled_width = normalised_width;
scaled_height = ( output_ar * normalised_height ) / input_ar + 0.5;
scaled_height = rint( 0.5 + ( output_ar * normalised_height ) / input_ar );
}

// Now calculate the actual image size that we want
owidth = scaled_width * owidth / normalised_width;
oheight = scaled_height * oheight / normalised_height;
owidth = rint( 0.5 + scaled_width * owidth / normalised_width );
oheight = rint( 0.5 + scaled_height * oheight / normalised_height );

// Tell frame we have conformed the aspect to the consumer
mlt_frame_set_aspect_ratio( this, mlt_properties_get_double( properties, "consumer_aspect_ratio" ) );
Expand Down
1 change: 1 addition & 0 deletions src/modules/core/filter_watermark.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
mlt_frame_set_position( b_frame, position );
mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
mlt_properties_set_int( b_props, "consumer_deinterlace", mlt_properties_get_double( a_props, "consumer_deinterlace" ) );
mlt_properties_set_int( b_props, "output_ratio", mlt_properties_get_double( a_props, "output_ratio" ) );

// Check for the special case - no aspect ratio means no problem :-)
if ( mlt_frame_get_aspect_ratio( b_frame ) == 0 )
Expand Down
1 change: 1 addition & 0 deletions src/modules/core/producer_colour.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
// Now update properties so we free the copy after
mlt_properties_set_data( properties, "image", copy, size, mlt_pool_release, NULL );
mlt_properties_set_data( properties, "alpha", alpha, size >> 1, mlt_pool_release, NULL );
mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
}

// Pass on the image
Expand Down
Loading

0 comments on commit c974f8e

Please sign in to comment.