]> git.sesse.net Git - mlt/blobdiff - src/modules/avformat/filter_swscale.c
Correct maximum matrix size for DeconvolutionSharpenEffect.
[mlt] / src / modules / avformat / filter_swscale.c
index a82b5e7ccd5d1338040e0ea9af4cc973a4029178..9a47076962f7894930b15131c885a5bbe6777fbf 100644 (file)
 
 
 // ffmpeg Header files
-#include <avformat.h>
-#include <swscale.h>
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#if LIBAVUTIL_VERSION_INT < (50<<16)
-#define PIX_FMT_RGB32 PIX_FMT_RGBA32
-#define PIX_FMT_YUYV422 PIX_FMT_YUV422
-#endif
-
 static inline int convert_mlt_to_av_cs( mlt_image_format format )
 {
        int value = 0;
@@ -47,7 +42,7 @@ static inline int convert_mlt_to_av_cs( mlt_image_format format )
                        break;
                case mlt_image_rgb24a:
                case mlt_image_opengl:
-                       value = PIX_FMT_RGB32;
+                       value = PIX_FMT_RGBA;
                        break;
                case mlt_image_yuv422:
                        value = PIX_FMT_YUYV422;
@@ -55,7 +50,7 @@ static inline int convert_mlt_to_av_cs( mlt_image_format format )
                case mlt_image_yuv420p:
                        value = PIX_FMT_YUV420P;
                        break;
-               case mlt_image_none:
+               default:
                        fprintf( stderr, "Invalid format...\n" );
                        break;
        }
@@ -63,10 +58,10 @@ static inline int convert_mlt_to_av_cs( mlt_image_format format )
        return value;
 }
 
-static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight )
+static int filter_scale( mlt_frame frame, uint8_t **image, mlt_image_format *format, int iwidth, int iheight, int owidth, int oheight )
 {
        // Get the properties
-       mlt_properties properties = MLT_FRAME_PROPERTIES( this );
+       mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
 
        // Get the requested interpolation method
        char *interps = mlt_properties_get( properties, "rescale.interp" );
@@ -95,19 +90,19 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
 
        // Determine the bytes per pixel
        int bpp;
+       mlt_image_format_size( *format, 0, 0, &bpp );
+
+       // Set swscale flags to get good quality
        switch ( *format )
        {
                case mlt_image_yuv422:
-                       bpp = 2;
                        interp |= SWS_FULL_CHR_H_INP;
                        break;
                case mlt_image_rgb24:
-                       bpp = 3;
                        interp |= SWS_FULL_CHR_H_INT;
                        break;
                case mlt_image_rgb24a:
                case mlt_image_opengl:
-                       bpp = 4;
                        interp |= SWS_FULL_CHR_H_INT;
                        break;
                default:
@@ -142,13 +137,11 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        if ( context )
        {
                // Perform the scaling
-               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+               sws_scale( context, (const uint8_t* const*) input.data, input.linesize, 0, iheight, output.data, output.linesize);
                sws_freeContext( context );
        
                // Now update the frame
-               mlt_properties_set_data( properties, "image", output.data[0], 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( frame, output.data[0], owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
        
                // Return the output
                *image = output.data[0];
@@ -159,7 +152,7 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                if ( alpha_size > 0 && alpha_size != ( owidth * oheight ) )
                {
                        // Create the context and output image
-                       uint8_t *alpha = mlt_frame_get_alpha_mask( this );
+                       uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
                        if ( alpha )
                        {
                                avformat = PIX_FMT_GRAY8;
@@ -169,11 +162,11 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                                avpicture_fill( &output, outbuf, avformat, owidth, oheight );
        
                                // Perform the scaling
-                               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+                               sws_scale( context, (const uint8_t* const*) input.data, input.linesize, 0, iheight, output.data, output.linesize);
                                sws_freeContext( context );
        
                                // Set it back on the frame
-                               mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output.data[0], owidth * oheight, mlt_pool_release, NULL );
+                               mlt_frame_set_alpha( frame, output.data[0], owidth * oheight, mlt_pool_release );
                        }
                }
        
@@ -193,22 +186,24 @@ mlt_filter filter_swscale_init( mlt_profile profile, void *arg )
        // Test to see if swscale accepts the arg as resolution
        if ( arg )
        {
-               int width = (int) arg;
-               struct SwsContext *context = sws_getContext( width, width, PIX_FMT_RGB32, 64, 64, PIX_FMT_RGB32, SWS_BILINEAR, NULL, NULL, NULL);
-               if ( context )
-                       sws_freeContext( context );
-               else
-                       return NULL;
-       }               
+               int *width = (int*) arg;
+               if ( *width > 0 )
+               {
+                       struct SwsContext *context = sws_getContext( *width, *width, PIX_FMT_RGB32, 64, 64, PIX_FMT_RGB32, SWS_BILINEAR, NULL, NULL, NULL);
+                       if ( context )
+                               sws_freeContext( context );
+                       else
+                               return NULL;
+       }       }
 
        // Create a new scaler
-       mlt_filter this = mlt_factory_filter( profile, "rescale", NULL );
+       mlt_filter filter = mlt_factory_filter( profile, "rescale", NULL );
        
        // If successful, then initialise it
-       if ( this != NULL )
+       if ( filter != NULL )
        {
                // Get the properties
-               mlt_properties properties = MLT_FILTER_PROPERTIES( this );
+               mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
 
                // Set the inerpolation
                mlt_properties_set( properties, "interpolation", "bilinear" );
@@ -217,5 +212,5 @@ mlt_filter filter_swscale_init( mlt_profile profile, void *arg )
                mlt_properties_set_data( properties, "method", filter_scale, 0, NULL, NULL );
        }
 
-       return this;
+       return filter;
 }