Correction for ETV specific filters
[melted] / src / framework / mlt_frame.c
index a0a4732..5a86627 100644 (file)
@@ -569,7 +569,7 @@ uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth,
 {
        uint8_t *output = NULL;
 
-       if ( input != NULL && ( iwidth != owidth || iheight != oheight ) )
+       if ( input != NULL && ( iwidth != owidth || iheight != oheight ) && ( owidth > 6 && oheight > 6 ) )
        {
                iwidth = iwidth - ( iwidth % 2 );
                owidth = owidth - ( owidth % 2 );
@@ -651,14 +651,21 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        int istride = iwidth * 2;
        int ostride = owidth * 2;
 
-       iwidth = iwidth - ( iwidth % 4 );
-       owidth = owidth - ( owidth % 4 );
+       iwidth = iwidth - ( iwidth % 2 );
+       owidth = owidth - ( owidth % 2 );
        //iheight = iheight - ( iheight % 2 );
        //oheight = oheight - ( oheight % 2 );
-
+       
        // Optimisation point
-       if ( iwidth == owidth && iheight == oheight )
+       if ( output == NULL || input == NULL || ( owidth <= 6 || oheight <= 6 || iwidth <= 6 || oheight <= 6 ) )
+       {
+               return;
+       }
+       else if ( iwidth == owidth && iheight == oheight )
+       {
                memcpy( output, input, iheight * istride );
+               return;
+       }
 
        // Coordinates (0,0 is middle of output)
        int y;
@@ -674,7 +681,7 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        uint8_t *out_ptr = out_line;
 
        // Calculate a middle and possibly invalid pointer in the input
-       uint8_t *in_middle = input + istride * ( iheight / 2 ) + ( iwidth / 2 ) * 2;
+       uint8_t *in_middle = input + istride * ( iheight / 2 ) + iwidth;
        int in_line = - in_y_range * istride - in_x_range * 2;
 
        int elements;
@@ -690,10 +697,18 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        }
 
        int active_width = 2 * iwidth;
-       int inactive_width = out_x_range - in_x_range;
+       int left_inactive_width = out_x_range - in_x_range;
+       int right_inactive_width = left_inactive_width;
        uint8_t *p = NULL;
        uint8_t *end = NULL;
 
+       if ( in_line % 4 )
+       {
+               active_width -= 2;
+               in_middle += 2;
+               right_inactive_width += 2;
+       }
+
        // Loop for the entirety of our output height.
        while ( iheight -- )
        {
@@ -701,7 +716,7 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
                out_ptr = out_line;
 
                // Fill the outer part with black
-               elements = inactive_width;
+               elements = left_inactive_width;
                while ( elements -- )
                {
                        *out_ptr ++ = 16;
@@ -718,7 +733,7 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
                }
 
                // Fill the outer part with black
-               elements = inactive_width;
+               elements = right_inactive_width;
                while ( elements -- )
                {
                        *out_ptr ++ = 16;