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 <framework/mlt_filter.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 ) );
35 int invert
= mlt_deque_pop_back_int( MLT_FRAME_IMAGE_STACK( this ) );
38 if ( mlt_frame_get_image( this, image
, format
, width
, height
, writable
) == 0 )
41 uint8_t A
= invert?
235 : 16;
42 uint8_t B
= invert?
16 : 235;
43 int size
= *width
* *height
;
58 uint8_t *alpha
= mlt_frame_get_alpha_mask( this );
61 if ( *alpha
++ < midpoint
)
73 /** Filter processing.
76 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
78 int midpoint
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "midpoint" );
79 int use_alpha
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "use_alpha" );
80 int invert
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "invert" );
81 mlt_deque_push_back_int( MLT_FRAME_IMAGE_STACK( frame
), invert
);
82 mlt_deque_push_back_int( MLT_FRAME_IMAGE_STACK( frame
), midpoint
);
83 mlt_deque_push_back_int( MLT_FRAME_IMAGE_STACK( frame
), use_alpha
);
84 mlt_frame_push_get_image( frame
, filter_get_image
);
88 /** Constructor for the filter.
91 mlt_filter
filter_mono_init( mlt_profile profile
, mlt_service_type type
, const char *id
, char *arg
)
93 mlt_filter
this = mlt_filter_new( );
96 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "midpoint", 128 );
97 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "use_alpha", 0 );
98 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "invert", 0 );
99 this->process
= filter_process
;