2 * filter_mono.c -- Arbitrary alpha channel shaping
3 * Copyright (C) 2005 Visual Media Fx Inc.
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 Lesser 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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser 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_mono.h"
23 #include <framework/mlt_factory.h>
24 #include <framework/mlt_frame.h>
25 #include <framework/mlt_producer.h>
26 #include <framework/mlt_geometry.h>
28 /** Get the images and apply the luminance of the mask to the alpha of the frame.
31 static int filter_get_image( mlt_frame
this, uint8_t **image
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
33 int use_alpha
= mlt_deque_pop_back_int( MLT_FRAME_IMAGE_STACK( this ) );
34 int midpoint
= mlt_deque_pop_back_int( MLT_FRAME_IMAGE_STACK( this ) );
37 if ( mlt_frame_get_image( this, image
, format
, width
, height
, writable
) == 0 )
40 int size
= *width
* *height
;
55 uint8_t *alpha
= mlt_frame_get_alpha_mask( this );
58 if ( *alpha
++ < midpoint
)
70 /** Filter processing.
73 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
75 int midpoint
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "midpoint" );
76 int use_alpha
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "use_alpha" );
77 mlt_deque_push_back_int( MLT_FRAME_IMAGE_STACK( frame
), midpoint
);
78 mlt_deque_push_back_int( MLT_FRAME_IMAGE_STACK( frame
), use_alpha
);
79 mlt_frame_push_get_image( frame
, filter_get_image
);
83 /** Constructor for the filter.
86 mlt_filter
filter_mono_init( char *arg
)
88 mlt_filter
this = mlt_filter_new( );
91 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "midpoint", 128 );
92 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "use_alpha", 0 );
93 this->process
= filter_process
;