From 87bb0ebbb783654264b590084f140cc2c13bf206 Mon Sep 17 00:00:00 2001 From: ddennedy Date: Sun, 1 Jun 2008 23:34:07 +0000 Subject: [PATCH] filter_resize,c, filter_composite.c: bugfix redundant rounding. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1132 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/modules/core/filter_resize.c | 11 ++++---- src/modules/core/transition_composite.c | 35 ++++++++++++++----------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/modules/core/filter_resize.c b/src/modules/core/filter_resize.c index e7e7fbe2..68244bfc 100644 --- a/src/modules/core/filter_resize.c +++ b/src/modules/core/filter_resize.c @@ -89,22 +89,23 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * double input_ar = aspect_ratio * real_width / real_height; double output_ar = mlt_properties_get_double( properties, "consumer_aspect_ratio" ) * owidth / oheight; - //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 ); +// fprintf( stderr, "real %dx%d normalised %dx%d output %dx%d sar %f in-dar %f out-dar %f\n", +// real_width, real_height, normalised_width, normalised_height, owidth, oheight, aspect_ratio, input_ar, output_ar); // Optimised for the input_ar > output_ar case (e.g. widescreen on standard) - int scaled_width = rint( 0.5 + ( input_ar * normalised_width ) / output_ar ); + int scaled_width = rint( ( 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 = rint( 0.5 + ( output_ar * normalised_height ) / input_ar ); + scaled_height = rint( ( output_ar * normalised_height ) / input_ar ); } // Now calculate the actual image size that we want - owidth = rint( 0.5 + scaled_width * owidth / normalised_width ); - oheight = rint( 0.5 + scaled_height * oheight / normalised_height ); + owidth = rint( scaled_width * owidth / normalised_width ); + oheight = rint( 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" ) ); diff --git a/src/modules/core/transition_composite.c b/src/modules/core/transition_composite.c index 9104073b..87d013e9 100644 --- a/src/modules/core/transition_composite.c +++ b/src/modules/core/transition_composite.c @@ -459,8 +459,8 @@ static int composite_yuv( uint8_t *p_dest, int width_dest, int height_dest, uint int stride_dest = width_dest * bpp; // Adjust to consumer scale - int x = rint( 0.5 + geometry.item.x * width_dest / geometry.nw ); - int y = rint( 0.5 + geometry.item.y * height_dest / geometry.nh ); + int x = rint( geometry.item.x * width_dest / geometry.nw ); + int y = rint( geometry.item.y * height_dest / geometry.nh ); int uneven_x = ( x % 2 ); // optimization points - no work to do @@ -729,18 +729,21 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** double consumer_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" ); double background_ar = mlt_properties_get_double( b_props, "output_ratio" ); double output_ar = background_ar != 0.0 ? background_ar : consumer_ar; - int scaled_width = rint( 0.5 + ( input_ar == 0.0 ? output_ar : input_ar ) / output_ar * real_width ); + int scaled_width = rint( ( input_ar == 0.0 ? output_ar : input_ar ) / output_ar * real_width ); int scaled_height = real_height; +// fprintf(stderr, "%s: scaled %dx%d norm %dx%d real %dx%d output_ar %f => %f\n", __FILE__, +// scaled_width, scaled_height, normalised_width, normalised_height, real_width, real_height, +// background_ar, output_ar); // Now ensure that our images fit in the normalised frame if ( scaled_width > normalised_width ) { - scaled_height = rint( 0.5 + scaled_height * normalised_width / scaled_width ); + scaled_height = rint( scaled_height * normalised_width / scaled_width ); scaled_width = normalised_width; } if ( scaled_height > normalised_height ) { - scaled_width = rint( 0.5 + scaled_width * normalised_height / scaled_height ); + scaled_width = rint( scaled_width * normalised_height / scaled_height ); scaled_height = normalised_height; } @@ -750,12 +753,12 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** { if ( scaled_height < normalised_height && scaled_width * normalised_height / scaled_height <= normalised_width ) { - scaled_width = rint( 0.5 + scaled_width * normalised_height / scaled_height ); + scaled_width = rint( scaled_width * normalised_height / scaled_height ); scaled_height = normalised_height; } else if ( scaled_width < normalised_width && scaled_height * normalised_width / scaled_width < normalised_height ) { - scaled_height = rint( 0.5 + scaled_height * normalised_width / scaled_width ); + scaled_height = rint( scaled_height * normalised_width / scaled_width ); scaled_width = normalised_width; } } @@ -783,8 +786,10 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t ** alignment_calculate( geometry ); // Adjust to consumer scale - *width = rint( 0.5 + geometry->sw * *width / geometry->nw ); - *height = rint( 0.5 + geometry->sh * *height / geometry->nh ); + *width = rint( geometry->sw * *width / geometry->nw ); + *height = rint( geometry->sh * *height / geometry->nh ); +// fprintf(stderr, "%s: scaled %dx%d norm %dx%d resize %dx%d\n", __FILE__, +// geometry->sw, geometry->sh, geometry->nw, geometry->nh, *width, *height); ret = mlt_frame_get_image( b_frame, image, &format, width, height, 1 ); @@ -901,10 +906,10 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_pos composite_calculate( this, &result, a_frame, position ); // Need to scale down to actual dimensions - x = rint( 0.5 + result.item.x * width / result.nw ); - y = rint( 0.5 + result.item.y * height / result.nh ); - w = rint( 0.5 + result.item.w * width / result.nw ); - h = rint( 0.5 + result.item.h * height / result.nh ); + x = rint( result.item.x * width / result.nw ); + y = rint( result.item.y * height / result.nh ); + w = rint( result.item.w * width / result.nw ); + h = rint( result.item.h * height / result.nh ); if ( x % 2 ) { @@ -1138,9 +1143,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f if ( mlt_properties_get_int( properties, "titles" ) ) { - result.item.w = rint( 0.5 + *width * ( result.item.w / result.nw ) ); + result.item.w = rint( *width * ( result.item.w / result.nw ) ); result.nw = result.item.w; - result.item.h = rint( 0.5 + *height * ( result.item.h / result.nh ) ); + result.item.h = rint( *height * ( result.item.h / result.nh ) ); result.nh = *height; result.sw = width_b; result.sh = height_b; -- 2.39.2