2 * filter_mirror.c -- mirror filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <framework/mlt_filter.h>
22 #include <framework/mlt_frame.h>
31 static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
33 // Pop the mirror filter from the stack
34 mlt_filter this = mlt_frame_pop_service( frame );
36 // Get the mirror type
37 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
40 char *mirror = mlt_properties_get( properties, "mirror" );
42 // Determine if reverse is required
43 int reverse = mlt_properties_get_int( properties, "reverse" );
46 int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
49 uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
51 // If we have an image of the right colour space
52 if ( error == 0 && *format == mlt_image_yuv422 )
57 if ( !strcmp( mirror, "horizontal" ) )
64 int uneven_w = ( *width % 2 ) * 2;
65 for ( i = 0; i < *height; i ++ )
67 p = ( uint8_t * )*image + i * *width * 2;
69 a = alpha + i * *width;
76 *p ++ = *( q - 3 - uneven_w );
78 *p ++ = *( q - 1 - uneven_w );
89 *( q - 3 - uneven_w ) = *p ++;
91 *( q - 1 - uneven_w ) = *p ++;
99 else if ( !strcmp( mirror, "vertical" ) )
101 uint16_t *end = ( uint16_t *)*image + *width * *height;
108 for ( i = 0; i < hh; i ++ )
110 p = ( uint16_t * )*image + i * *width;
111 q = end - ( i + 1 ) * *width;
113 a = alpha + i * *width;
114 b = alpha + ( *height - i - 1 ) * *width;
133 else if ( !strcmp( mirror, "diagonal" ) )
135 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
142 int uneven_w = ( *width % 2 ) * 2;
143 for ( i = 0; i < *height; i ++ )
145 p = ( uint8_t * )*image + i * *width * 2;
146 q = end - i * *width * 2;
147 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
148 a = alpha + i * *width;
149 b = alpha + ( *height - i - 1 ) * *width;
155 *p ++ = *( q - 3 - uneven_w );
157 *p ++ = *( q - 1 - uneven_w );
168 *( q - 3 - uneven_w ) = *p ++;
170 *( q - 1 - uneven_w ) = *p ++;
178 else if ( !strcmp( mirror, "xdiagonal" ) )
180 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
187 int uneven_w = ( *width % 2 ) * 2;
188 for ( i = 0; i < *height; i ++ )
190 p = ( uint8_t * )*image + ( i + 1 ) * *width * 2;
191 q = end - ( i + 1 ) * *width * 2;
192 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
193 a = alpha + ( i + 1 ) * *width - 1;
194 b = alpha + ( *height - i - 1 ) * *width;
200 *q ++ = *( p - 3 - uneven_w );
202 *q ++ = *( p - 1 - uneven_w );
213 *( p - 3 - uneven_w ) = *q ++;
215 *( p - 1 - uneven_w ) = *q ++;
223 else if ( !strcmp( mirror, "flip" ) )
232 int uneven_w = ( *width % 2 ) * 2;
233 for ( i = 0; i < *height; i ++ )
235 p = ( uint8_t * )*image + i * *width * 2;
237 a = alpha + i * *width;
242 t[ 1 ] = p[ 1 + uneven_w ];
244 t[ 3 ] = p[ 3 + uneven_w ];
246 *p ++ = *( q - 3 - uneven_w );
248 *p ++ = *( q - 1 - uneven_w );
262 else if ( !strcmp( mirror, "flop" ) )
264 uint16_t *end = ( uint16_t *)*image + *width * *height;
273 for ( i = 0; i < hh; i ++ )
275 p = ( uint16_t * )*image + i * *width;
276 q = end - ( i + 1 ) * *width;
277 a = alpha + i * *width;
278 b = alpha + ( *height - i - 1 ) * *width;
297 /** Filter processing.
300 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
302 // Push the service on to the stack
303 mlt_frame_push_service( frame, this );
305 // Push the filter method on to the stack
306 mlt_frame_push_service( frame, filter_get_image );
311 /** Constructor for the filter.
314 mlt_filter filter_mirror_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
316 // Construct a new filter
317 mlt_filter this = mlt_filter_new( );
319 // If we have a filter, initialise it
322 // Get the properties
323 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
325 // Set the default mirror type
326 mlt_properties_set_or_default( properties, "mirror", arg, "horizontal" );
328 // Assign the process method
329 this->process = filter_process;