X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fvmfx%2Ffilter_chroma_hold.c;h=07ca4a800e25b218d87bdfbba9c881fd71af4006;hb=ef765a5b52c93b5044a390fbe1c31a412cf59888;hp=2992ceb5102304d8dd3f8d56b16bd568e3b19c66;hpb=66ee48cf0b9448e670cfa19dfbbdc06193288181;p=melted diff --git a/src/modules/vmfx/filter_chroma_hold.c b/src/modules/vmfx/filter_chroma_hold.c index 2992ceb..07ca4a8 100644 --- a/src/modules/vmfx/filter_chroma_hold.c +++ b/src/modules/vmfx/filter_chroma_hold.c @@ -18,7 +18,7 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "filter_chroma.h" +#include #include #include #include @@ -30,9 +30,12 @@ static inline int in_range( uint8_t v, uint8_t c, int var ) return ( ( int )v >= c - var ) && ( ( int )v <= c + var ); } -static inline uint8_t alpha_value( uint8_t a, uint8_t *p, uint8_t u, uint8_t v, int var ) +static inline uint8_t alpha_value( uint8_t a, uint8_t *p, uint8_t u, uint8_t v, int var, int odd ) { - return ( in_range( *( p + 1 ), u, var ) && in_range( *( p + 3 ), v, var ) ) ? 0 : a; + if ( odd == 0 ) + return ( in_range( *( p + 1 ), u, var ) && in_range( *( p + 3 ), v, var ) ) ? 0 : a; + else + return ( in_range( ( *( p + 1 ) + *( p + 5 ) ) / 2, u, var ) && in_range( ( *( p + 3 ) + *( p + 7 ) ) / 2, v, var ) ) ? 0 : a; } /** Get the images and map the chroma to the alpha of the frame. @@ -41,12 +44,11 @@ static inline uint8_t alpha_value( uint8_t a, uint8_t *p, uint8_t u, uint8_t v, static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter this = mlt_frame_pop_service( frame ); - char *key = mlt_properties_get( MLT_FILTER_PROPERTIES( this ), "key" ); int variance = 200 * mlt_properties_get_double( MLT_FILTER_PROPERTIES( this ), "variance" ); - int32_t key_val = strtol( key, &key, 0 ); - uint8_t b = key_val & 0xff; - uint8_t g = ( key_val >> 8 ) & 0xff; - uint8_t r = ( key_val >> 16 ) & 0xff; + int32_t key_val = mlt_properties_get_int( MLT_FILTER_PROPERTIES( this ), "key" ); + uint8_t r = ( key_val >> 24 ) & 0xff; + uint8_t g = ( key_val >> 16 ) & 0xff; + uint8_t b = ( key_val >> 8 ) & 0xff; uint8_t y, u, v; RGB2YUV( r, g, b, y, u, v ); @@ -58,18 +60,13 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format int size = *width * *height / 2; while ( size -- ) { - alpha = alpha_value( 255, p, u, v, variance ); - p ++; + alpha = alpha_value( 255, p, u, v, variance, 0 ); if ( alpha ) - *p ++ = 128; - else - p ++; - alpha = alpha_value( 255, p, v, u, variance ); - p ++; + *( p + 1 )= 128; + alpha = alpha_value( 255, p, u, v, variance, 1 ); if ( alpha ) - *p ++ = 128; - else - p ++; + *( p + 3 ) = 128; + p += 4; } } @@ -89,13 +86,13 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) /** Constructor for the filter. */ -mlt_filter filter_chroma_hold_init( char *arg ) +mlt_filter filter_chroma_hold_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter this = mlt_filter_new( ); if ( this != NULL ) { - mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "key", arg == NULL ? "0xc00000" : arg ); - mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "variance", 0.3 ); + mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "key", arg == NULL ? "0xc0000000" : arg ); + mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "variance", 0.15 ); this->process = filter_process; } return this;