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 );
50 uint8_t *alpha = mlt_frame_get_alpha_mask( frame );
52 // If we have an image of the right colour space
53 if ( error == 0 && *format == mlt_image_yuv422 )
58 if ( !strcmp( mirror, "horizontal" ) )
65 int uneven_w = ( *width % 2 ) * 2;
66 for ( i = 0; i < *height; i ++ )
68 p = ( uint8_t * )*image + i * *width * 2;
70 a = alpha + i * *width;
77 *p ++ = *( q - 3 - uneven_w );
79 *p ++ = *( q - 1 - uneven_w );
90 *( q - 3 - uneven_w ) = *p ++;
92 *( q - 1 - uneven_w ) = *p ++;
100 else if ( !strcmp( mirror, "vertical" ) )
102 uint16_t *end = ( uint16_t *)*image + *width * *height;
109 for ( i = 0; i < hh; i ++ )
111 p = ( uint16_t * )*image + i * *width;
112 q = end - ( i + 1 ) * *width;
114 a = alpha + i * *width;
115 b = alpha + ( *height - i - 1 ) * *width;
134 else if ( !strcmp( mirror, "diagonal" ) )
136 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
143 int uneven_w = ( *width % 2 ) * 2;
144 for ( i = 0; i < *height; i ++ )
146 p = ( uint8_t * )*image + i * *width * 2;
147 q = end - i * *width * 2;
148 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
149 a = alpha + i * *width;
150 b = alpha + ( *height - i - 1 ) * *width;
156 *p ++ = *( q - 3 - uneven_w );
158 *p ++ = *( q - 1 - uneven_w );
169 *( q - 3 - uneven_w ) = *p ++;
171 *( q - 1 - uneven_w ) = *p ++;
179 else if ( !strcmp( mirror, "xdiagonal" ) )
181 uint8_t *end = ( uint8_t *)*image + *width * *height * 2;
188 int uneven_w = ( *width % 2 ) * 2;
189 for ( i = 0; i < *height; i ++ )
191 p = ( uint8_t * )*image + ( i + 1 ) * *width * 2;
192 q = end - ( i + 1 ) * *width * 2;
193 j = ( ( *width * ( *height - i ) ) / *height ) / 2;
194 a = alpha + ( i + 1 ) * *width - 1;
195 b = alpha + ( *height - i - 1 ) * *width;
201 *q ++ = *( p - 3 - uneven_w );
203 *q ++ = *( p - 1 - uneven_w );
214 *( p - 3 - uneven_w ) = *q ++;
216 *( p - 1 - uneven_w ) = *q ++;
224 else if ( !strcmp( mirror, "flip" ) )
233 int uneven_w = ( *width % 2 ) * 2;
234 for ( i = 0; i < *height; i ++ )
236 p = ( uint8_t * )*image + i * *width * 2;
238 a = alpha + i * *width;
243 t[ 1 ] = p[ 1 + uneven_w ];
245 t[ 3 ] = p[ 3 + uneven_w ];
247 *p ++ = *( q - 3 - uneven_w );
249 *p ++ = *( q - 1 - uneven_w );
263 else if ( !strcmp( mirror, "flop" ) )
265 uint16_t *end = ( uint16_t *)*image + *width * *height;
274 for ( i = 0; i < hh; i ++ )
276 p = ( uint16_t * )*image + i * *width;
277 q = end - ( i + 1 ) * *width;
278 a = alpha + i * *width;
279 b = alpha + ( *height - i - 1 ) * *width;
298 /** Filter processing.
301 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
303 // Push the service on to the stack
304 mlt_frame_push_service( frame, this );
306 // Push the filter method on to the stack
307 mlt_frame_push_service( frame, filter_get_image );
312 /** Constructor for the filter.
315 mlt_filter filter_mirror_init( void *arg )
317 // Construct a new filter
318 mlt_filter this = mlt_filter_new( );
320 // If we have a filter, initialise it
323 // Get the properties
324 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
326 // Set the default mirror type
327 mlt_properties_set_or_default( properties, "mirror", arg, "horizontal" );
329 // Assign the process method
330 this->process = filter_process;