filehandler.cc
[melted] / src / modules / core / filter_mirror.c
index bc8927a..a7cb697 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" );
@@ -63,7 +63,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                q = p + *width * 2;
                                if ( !reverse )
                                {
-                                       while ( p != q )
+                                       while ( p < q )
                                        {
                                                *p ++ = *( q - 2 );
                                                *p ++ = *( q - 3 );
@@ -74,7 +74,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                }
                                else
                                {
-                                       while ( p != q )
+                                       while ( p < q )
                                        {
                                                *( q - 2 ) = *p ++;
                                                *( q - 3 ) = *p ++;
@@ -95,7 +95,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        for ( i = 0; i < hh; i ++ )
                        {
                                p = ( uint16_t * )*image + i * *width;
-                               q = end - i * *width;
+                               q = end - ( i + 1 ) * *width;
                                j = *width;
                                if ( !reverse )
                                {
@@ -145,6 +145,42 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                }
                        }
                }
+               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;
+                       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;
+                               if ( !reverse )
+                               {
+                                       while ( j -- )
+                                       {
+                                               *q ++ = *( p - 2 );
+                                               *q ++ = *( p - 3 );
+                                               *q ++ = *( p - 4 );
+                                               *q ++ = *( p - 1 );
+                                               p -= 4;
+                                       }
+                               }
+                               else
+                               {
+                                       while ( j -- )
+                                       {
+                                               *( p - 2 ) = *q ++;
+                                               *( p - 3 ) = *q ++;
+                                               *( p - 4 ) = *q ++;
+                                               *( p - 1 ) = *q ++;
+                                               p -= 4;
+                                       }
+                               }
+                       }
+               }
                else if ( !strcmp( mirror, "flip" ) )
                {
                        uint8_t t[ 4 ];
@@ -155,7 +191,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        {
                                p = ( uint8_t * )*image + i * *width * 2;
                                q = p + *width * 2;
-                               while ( p != q )
+                               while ( p < q )
                                {
                                        t[ 0 ] = p[ 0 ];
                                        t[ 1 ] = p[ 1 ];
@@ -183,7 +219,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        for ( i = 0; i < hh; i ++ )
                        {
                                p = ( uint16_t * )*image + i * *width;
-                               q = end - i * *width;
+                               q = end - ( i + 1 ) * *width;
                                j = *width;
                                while ( j -- )
                                {
@@ -225,7 +261,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" );