+ Added an option to override alignment and transparent borders for compositing
[melted] / src / modules / core / filter_mirror.c
index bc8927a..430e401 100644 (file)
@@ -35,7 +35,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        mlt_filter this = mlt_frame_pop_service( frame );
 
        // Get the mirror type
-       mlt_properties properties = mlt_filter_properties( this );
+       mlt_properties properties = MLT_FILTER_PROPERTIES( this );
 
        // Get the properties
        char *mirror = mlt_properties_get( properties, "mirror" );
@@ -46,6 +46,9 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Get the image
        int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
 
+       // Get the alpha
+       uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
+
        // If we have an image of the right colour space
        if ( error == 0 && *format == mlt_image_yuv422 )
        {
@@ -56,31 +59,40 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                {
                        uint8_t *p = NULL;
                        uint8_t *q = NULL;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
                        int i;
+                       int uneven_w = ( *width % 2 ) * 2;
                        for ( i = 0; i < *height; i ++ )
                        {
                                p = ( uint8_t * )*image + i * *width * 2;
                                q = p + *width * 2;
+                               a = alpha + i * *width;
+                               b = a + *width - 1;
                                if ( !reverse )
                                {
-                                       while ( p != q )
+                                       while ( p < q )
                                        {
                                                *p ++ = *( q - 2 );
-                                               *p ++ = *( q - 3 );
+                                               *p ++ = *( q - 3 - uneven_w );
                                                *p ++ = *( q - 4 );
-                                               *p ++ = *( q - 1 );
+                                               *p ++ = *( q - 1 - uneven_w );
                                                q -= 4;
+                                               *a ++ = *b --;
+                                               *a ++ = *b --;
                                        }
                                }
                                else
                                {
-                                       while ( p != q )
+                                       while ( p < q )
                                        {
                                                *( q - 2 ) = *p ++;
-                                               *( q - 3 ) = *p ++;
+                                               *( q - 3 - uneven_w ) = *p ++;
                                                *( q - 4 ) = *p ++;
-                                               *( q - 1 ) = *p ++;
+                                               *( q - 1 - uneven_w ) = *p ++;
                                                q -= 4;
+                                               *b -- = *a ++;
+                                               *b -- = *a ++;
                                        }
                                }
                        }
@@ -90,22 +102,32 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        uint16_t *end = ( uint16_t *)*image + *width * *height;
                        uint16_t *p = NULL;
                        uint16_t *q = NULL;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
                        int i;
                        int j;
                        for ( i = 0; i < hh; i ++ )
                        {
                                p = ( uint16_t * )*image + i * *width;
-                               q = end - i * *width;
+                               q = end - ( i + 1 ) * *width;
                                j = *width;
+                               a = alpha + i * *width;
+                               b = alpha + ( *height - i - 1 ) * *width;
                                if ( !reverse )
                                {
                                        while ( j -- )
+                                       {
                                                *p ++ = *q ++;
+                                               *a ++ = *b ++;
+                                       }
                                }
                                else
                                {
                                        while ( j -- )
+                                       {
                                                *q ++ = *p ++;
+                                               *b ++ = *a ++;
+                                       }
                                }
                        }
                }
@@ -114,22 +136,29 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
                        uint8_t *p = NULL;
                        uint8_t *q = NULL;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
                        int i;
                        int j;
+                       int uneven_w = ( *width % 2 ) * 2;
                        for ( i = 0; i < *height; i ++ )
                        {
                                p = ( uint8_t * )*image + i * *width * 2;
                                q = end - i * *width * 2;
                                j = ( ( *width * ( *height - i ) ) / *height ) / 2;
+                               a = alpha + i * *width;
+                               b = alpha + ( *height - i - 1 ) * *width;
                                if ( !reverse )
                                {
                                        while ( j -- )
                                        {
                                                *p ++ = *( q - 2 );
-                                               *p ++ = *( q - 3 );
+                                               *p ++ = *( q - 3 - uneven_w );
                                                *p ++ = *( q - 4 );
-                                               *p ++ = *( q - 1 );
+                                               *p ++ = *( q - 1 - uneven_w );
                                                q -= 4;
+                                               *a ++ = *b --;
+                                               *a ++ = *b --;
                                        }
                                }
                                else
@@ -137,10 +166,57 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                        while ( j -- )
                                        {
                                                *( q - 2 ) = *p ++;
-                                               *( q - 3 ) = *p ++;
+                                               *( q - 3 - uneven_w ) = *p ++;
                                                *( q - 4 ) = *p ++;
-                                               *( q - 1 ) = *p ++;
+                                               *( q - 1 - uneven_w ) = *p ++;
                                                q -= 4;
+                                               *b -- = *a ++;
+                                               *b -- = *a ++;
+                                       }
+                               }
+                       }
+               }
+               else if ( !strcmp( mirror, "xdiagonal" ) )
+               {
+                       uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
+                       uint8_t *p = NULL;
+                       uint8_t *q = NULL;
+                       int i;
+                       int j;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
+                       int uneven_w = ( *width % 2 ) * 2;
+                       for ( i = 0; i < *height; i ++ )
+                       {
+                               p = ( uint8_t * )*image + ( i + 1 ) * *width * 2;
+                               q = end - ( i + 1 ) * *width * 2;
+                               j = ( ( *width * ( *height - i ) ) / *height ) / 2;
+                               a = alpha + ( i + 1 ) * *width - 1;
+                               b = alpha + ( *height - i - 1 ) * *width;
+                               if ( !reverse )
+                               {
+                                       while ( j -- )
+                                       {
+                                               *q ++ = *( p - 2 );
+                                               *q ++ = *( p - 3 - uneven_w );
+                                               *q ++ = *( p - 4 );
+                                               *q ++ = *( p - 1 - uneven_w );
+                                               p -= 4;
+                                               *b ++ = *a --;
+                                               *b ++ = *a --;
+                                       }
+                               }
+                               else
+                               {
+                                       while ( j -- )
+                                       {
+                                               *( p - 2 ) = *q ++;
+                                               *( p - 3 - uneven_w ) = *q ++;
+                                               *( p - 4 ) = *q ++;
+                                               *( p - 1 - uneven_w ) = *q ++;
+                                               p -= 4;
+                                               *a -- = *b ++;
+                                               *a -- = *b ++;
                                        }
                                }
                        }
@@ -151,24 +227,36 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        uint8_t *p = NULL;
                        uint8_t *q = NULL;
                        int i;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
+                       uint8_t c;
+                       int uneven_w = ( *width % 2 ) * 2;
                        for ( i = 0; i < *height; i ++ )
                        {
                                p = ( uint8_t * )*image + i * *width * 2;
                                q = p + *width * 2;
-                               while ( p != q )
+                               a = alpha + i * *width;
+                               b = a + *width - 1;
+                               while ( p < q )
                                {
                                        t[ 0 ] = p[ 0 ];
-                                       t[ 1 ] = p[ 1 ];
+                                       t[ 1 ] = p[ 1 + uneven_w ];
                                        t[ 2 ] = p[ 2 ];
-                                       t[ 3 ] = p[ 3 ];
+                                       t[ 3 ] = p[ 3 + uneven_w ];
                                        *p ++ = *( q - 2 );
-                                       *p ++ = *( q - 3 );
+                                       *p ++ = *( q - 3 - uneven_w );
                                        *p ++ = *( q - 4 );
-                                       *p ++ = *( q - 1 );
+                                       *p ++ = *( q - 1 - uneven_w );
                                        *( -- q ) = t[ 3 ];
                                        *( -- q ) = t[ 0 ];
                                        *( -- q ) = t[ 1 ];
                                        *( -- q ) = t[ 2 ];
+                                       c = *a;
+                                       *a ++ = *b;
+                                       *b -- = c;
+                                       c = *a;
+                                       *a ++ = *b;
+                                       *b -- = c;
                                }
                        }
                }
@@ -178,18 +266,26 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        uint16_t *p = NULL;
                        uint16_t *q = NULL;
                        uint16_t t;
+                       uint8_t *a = NULL;
+                       uint8_t *b = NULL;
+                       uint8_t c;
                        int i;
                        int j;
                        for ( i = 0; i < hh; i ++ )
                        {
                                p = ( uint16_t * )*image + i * *width;
-                               q = end - i * *width;
+                               q = end - ( i + 1 ) * *width;
+                               a = alpha + i * *width;
+                               b = alpha + ( *height - i - 1 ) * *width;
                                j = *width;
                                while ( j -- )
                                {
                                        t = *p;
                                        *p ++ = *q;
                                        *q ++ = t;
+                                       c = *a;
+                                       *a ++ = *b;
+                                       *b ++ = c;
                                }
                        }
                }
@@ -225,7 +321,7 @@ mlt_filter filter_mirror_init( void *arg )
        if ( this != NULL )
        {
                // Get the properties
-               mlt_properties properties = mlt_filter_properties( this );
+               mlt_properties properties = MLT_FILTER_PROPERTIES( this );
 
                // Set the default mirror type
                mlt_properties_set_or_default( properties, "mirror", arg, "horizontal" );