2 * filter_mirror.c -- mirror filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "filter_mirror.h"
23 #include <framework/mlt_frame.h>
32 static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
34 // Pop the mirror filter from the stack
35 mlt_filter this = mlt_frame_pop_service( frame );
37 // Get the mirror type
38 mlt_properties properties = mlt_filter_properties( this );
41 char *mirror = mlt_properties_get( properties, "mirror" );
43 // Determine if reverse is required
44 int reverse = mlt_properties_get_int( properties, "reverse" );
47 int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
49 // If we have an image of the right colour space
50 if ( error == 0 && *format == mlt_image_yuv422 )
55 if ( !strcmp( mirror, "horizontal" ) )
60 for ( i = 0; i < *height; i ++ )
62 p = ( uint8_t * )*image + i * *width * 2;
88 else if ( !strcmp( mirror, "vertical" ) )
90 uint16_t *end = ( uint16_t *)*image + *width * *height;
95 for ( i = 0; i < hh; i ++ )
97 p = ( uint16_t * )*image + i * *width;
98 q = end - ( i + 1 ) * *width;
112 else if ( !strcmp( mirror, "diagonal" ) )
114 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
119 for ( i = 0; i < *height; i ++ )
121 p = ( uint8_t * )*image + i * *width * 2;
122 q = end - i * *width * 2;
123 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
148 else if ( !strcmp( mirror, "xdiagonal" ) )
150 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
155 for ( i = 0; i < *height; i ++ )
157 p = ( uint8_t * )*image + ( i + 1 ) * *width * 2;
158 q = end - ( i + 1 ) * *width * 2;
159 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
184 else if ( !strcmp( mirror, "flip" ) )
190 for ( i = 0; i < *height; i ++ )
192 p = ( uint8_t * )*image + i * *width * 2;
211 else if ( !strcmp( mirror, "flop" ) )
213 uint16_t *end = ( uint16_t *)*image + *width * *height;
219 for ( i = 0; i < hh; i ++ )
221 p = ( uint16_t * )*image + i * *width;
222 q = end - ( i + 1 ) * *width;
238 /** Filter processing.
241 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
243 // Push the service on to the stack
244 mlt_frame_push_service( frame, this );
246 // Push the filter method on to the stack
247 mlt_frame_push_service( frame, filter_get_image );
252 /** Constructor for the filter.
255 mlt_filter filter_mirror_init( void *arg )
257 // Construct a new filter
258 mlt_filter this = mlt_filter_new( );
260 // If we have a filter, initialise it
263 // Get the properties
264 mlt_properties properties = mlt_filter_properties( this );
266 // Set the default mirror type
267 mlt_properties_set_or_default( properties, "mirror", arg, "horizontal" );
269 // Assign the process method
270 this->process = filter_process;