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 for ( i
= 0; i
< *height
; i
++ )
67 p
= ( uint8_t * )*image
+ i
* *width
* 2;
69 a
= alpha
+ i
* *width
;
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 for ( i
= 0; i
< *height
; i
++ )
144 p
= ( uint8_t * )*image
+ i
* *width
* 2;
145 q
= end
- i
* *width
* 2;
146 j
= ( ( *width
* ( *height
- i
) ) / *height
) / 2;
147 a
= alpha
+ i
* *width
;
148 b
= alpha
+ ( *height
- i
- 1 ) * *width
;
177 else if ( !strcmp( mirror
, "xdiagonal" ) )
179 uint8_t *end
= ( uint8_t *)*image
+ *width
* *height
* 2;
186 for ( i
= 0; i
< *height
; i
++ )
188 p
= ( uint8_t * )*image
+ ( i
+ 1 ) * *width
* 2;
189 q
= end
- ( i
+ 1 ) * *width
* 2;
190 j
= ( ( *width
* ( *height
- i
) ) / *height
) / 2;
191 a
= alpha
+ ( i
+ 1 ) * *width
- 1;
192 b
= alpha
+ ( *height
- i
- 1 ) * *width
;
221 else if ( !strcmp( mirror
, "flip" ) )
230 for ( i
= 0; i
< *height
; i
++ )
232 p
= ( uint8_t * )*image
+ i
* *width
* 2;
234 a
= alpha
+ i
* *width
;
259 else if ( !strcmp( mirror
, "flop" ) )
261 uint16_t *end
= ( uint16_t *)*image
+ *width
* *height
;
270 for ( i
= 0; i
< hh
; i
++ )
272 p
= ( uint16_t * )*image
+ i
* *width
;
273 q
= end
- ( i
+ 1 ) * *width
;
274 a
= alpha
+ i
* *width
;
275 b
= alpha
+ ( *height
- i
- 1 ) * *width
;
294 /** Filter processing.
297 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
299 // Push the service on to the stack
300 mlt_frame_push_service( frame
, this );
302 // Push the filter method on to the stack
303 mlt_frame_push_service( frame
, filter_get_image
);
308 /** Constructor for the filter.
311 mlt_filter
filter_mirror_init( void *arg
)
313 // Construct a new filter
314 mlt_filter
this = mlt_filter_new( );
316 // If we have a filter, initialise it
319 // Get the properties
320 mlt_properties properties
= MLT_FILTER_PROPERTIES( this );
322 // Set the default mirror type
323 mlt_properties_set_or_default( properties
, "mirror", arg
, "horizontal" );
325 // Assign the process method
326 this->process
= filter_process
;