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;
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, "flip" ) )
154 for ( i = 0; i < *height; i ++ )
156 p = ( uint8_t * )*image + i * *width * 2;
175 else if ( !strcmp( mirror, "flop" ) )
177 uint16_t *end = ( uint16_t *)*image + *width * *height;
183 for ( i = 0; i < hh; i ++ )
185 p = ( uint16_t * )*image + i * *width;
186 q = end - i * *width;
202 /** Filter processing.
205 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
207 // Push the service on to the stack
208 mlt_frame_push_service( frame, this );
210 // Push the filter method on to the stack
211 mlt_frame_push_service( frame, filter_get_image );
216 /** Constructor for the filter.
219 mlt_filter filter_mirror_init( void *arg )
221 // Construct a new filter
222 mlt_filter this = mlt_filter_new( );
224 // If we have a filter, initialise it
227 // Get the properties
228 mlt_properties properties = mlt_filter_properties( this );
230 // Set the default mirror type
231 mlt_properties_set_or_default( properties, "mirror", arg, "horizontal" );
233 // Assign the process method
234 this->process = filter_process;