]> git.sesse.net Git - mlt/blobdiff - src/modules/core/filter_resize.c
add framerate adaption to consumer producer
[mlt] / src / modules / core / filter_resize.c
index 2d84b8f250f42ffd8cbdf3d8f4d342160161a010..3ba73ce29929ed9d0349a037bf6315feb2a356de 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <framework/mlt_filter.h>
 #include <framework/mlt_frame.h>
+#include <framework/mlt_profile.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -147,7 +148,7 @@ static uint8_t *frame_resize_image( mlt_frame this, int owidth, int oheight, int
        int iheight = mlt_properties_get_int( properties, "height" );
 
        // If width and height are correct, don't do anything
-       if ( iwidth != owidth || iheight != oheight )
+       if ( iwidth < owidth || iheight < oheight )
        {
                uint8_t alpha_value = mlt_properties_get_int( properties, "resize_alpha" );
 
@@ -158,9 +159,7 @@ static uint8_t *frame_resize_image( mlt_frame this, int owidth, int oheight, int
                resize_image( output, owidth, oheight, input, iwidth, iheight, bpp );
 
                // Now update the frame
-               mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * bpp, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_int( properties, "width", owidth );
-               mlt_properties_set_int( properties, "height", oheight );
+               mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
 
                // We should resize the alpha too
                if ( alpha && alpha_size >= iwidth * iheight )
@@ -168,7 +167,7 @@ static uint8_t *frame_resize_image( mlt_frame this, int owidth, int oheight, int
                        alpha = resize_alpha( alpha, owidth, oheight, iwidth, iheight, alpha_value );
                        if ( alpha )
                        {
-                               mlt_properties_set_data( properties, "alpha", alpha, owidth * oheight, ( mlt_destructor )mlt_pool_release, NULL );
+                               mlt_frame_set_alpha( this, alpha, owidth * oheight, mlt_pool_release );
                                this->get_alpha_mask = NULL;
                        }
                }
@@ -195,6 +194,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        // Retrieve the aspect ratio
        double aspect_ratio = mlt_deque_pop_back_double( MLT_FRAME_IMAGE_STACK( this ) );
+       double consumer_aspect = mlt_profile_sar( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ) );
 
        // Correct Width/height if necessary
        if ( *width == 0 || *height == 0 )
@@ -209,7 +209,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        // Check for the special case - no aspect ratio means no problem :-)
        if ( aspect_ratio == 0.0 )
-               aspect_ratio = mlt_properties_get_double( properties, "consumer_aspect_ratio" );
+               aspect_ratio = consumer_aspect;
 
        // Reset the aspect ratio
        mlt_properties_set_double( properties, "aspect_ratio", aspect_ratio );
@@ -231,7 +231,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                if ( real_height == 0 )
                        real_height = mlt_properties_get_int( properties, "height" );
                double input_ar = aspect_ratio * real_width / real_height;
-               double output_ar = mlt_properties_get_double( properties, "consumer_aspect_ratio" ) * owidth / oheight;
+               double output_ar = consumer_aspect * 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);
@@ -252,7 +252,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                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" ) );
+               mlt_frame_set_aspect_ratio( this, consumer_aspect );
        }
 
        mlt_properties_set_int( properties, "distort", 0 );
@@ -271,41 +271,29 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                // Get the requested scale operation
                char *op = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "scale" );
                int bpp;
-
-               switch ( *format )
-               {
-                       case mlt_image_yuv422:
-                               bpp = 2;
-                               break;
-                       case mlt_image_rgb24:
-                               bpp = 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               bpp = 4;
-                               break;
-                       default:
-                               // XXX: we only know how to resize packed formats
-                               return 1;
-               }
+               int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
+               int tff = mlt_properties_get_int( properties, "consumer_tff" );
 
                // Provides a manual override for misreported field order
                if ( mlt_properties_get( properties, "meta.top_field_first" ) )
                        mlt_properties_set_int( properties, "top_field_first", mlt_properties_get_int( properties, "meta.top_field_first" ) );
 
                // Correct field order if needed
-               if ( mlt_properties_get_int( properties, "top_field_first" ) == 1 &&
+               if ( mlt_properties_get_int( properties, "top_field_first" ) != tff &&
                     mlt_properties_get( properties, "progressive" ) &&
                     mlt_properties_get_int( properties, "progressive" ) == 0 )
                {
                        // Get the input image, width and height
-                       int size = owidth * oheight * bpp;
-                       uint8_t *ptr = *image + owidth * bpp;
-                       memmove( ptr, *image, size - owidth * bpp );
+                       uint8_t *new_image = mlt_pool_alloc( size );
+                       mlt_frame_set_image( this, new_image, size, mlt_pool_release );
+                       uint8_t *ptr = new_image + owidth * bpp;
+                       memcpy( new_image, *image, owidth * bpp );
+                       memcpy( ptr, *image, owidth * ( oheight - 1 ) * bpp );
+                       *image = new_image;
                        
                        // Set the normalised field order
-                       mlt_properties_set_int( properties, "top_field_first", 0 );
-                       mlt_properties_set_int( properties, "meta.top_field_first", 0 );
+                       mlt_properties_set_int( properties, "top_field_first", tff );
+                       mlt_properties_set_int( properties, "meta.top_field_first", tff );
                }
 
                if ( !strcmp( op, "affine" ) )