From: lilo_booter Date: Mon, 14 Aug 2006 09:31:14 +0000 (+0000) Subject: + Correction to uneven chroma samples X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=5ca02525045c7b3f6bb3ac33a903a1c88f8a2ea4;p=melted + Correction to uneven chroma samples git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@924 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/modules/vmfx/filter_chroma.c b/src/modules/vmfx/filter_chroma.c index 6d9384c..d9ab009 100644 --- a/src/modules/vmfx/filter_chroma.c +++ b/src/modules/vmfx/filter_chroma.c @@ -20,6 +20,7 @@ #include "filter_chroma.h" #include +#include #include #include #include @@ -30,9 +31,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. @@ -58,12 +62,11 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format int size = *width * *height / 2; while ( size -- ) { - *alpha = alpha_value( *alpha, p, u, v, variance ); + *alpha = alpha_value( *alpha, p, u, v, variance, 0 ); *alpha ++; - p += 2; - *alpha = alpha_value( *alpha, p, v, u, variance ); + *alpha = alpha_value( *alpha, p, u, v, variance, 1 ); alpha ++; - p += 2; + p += 4; } } @@ -88,8 +91,8 @@ mlt_filter filter_chroma_init( char *arg ) mlt_filter this = mlt_filter_new( ); if ( this != NULL ) { - mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "key", arg == NULL ? "0x00ff00" : arg ); - mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "variance", 0.3 ); + mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "key", arg == NULL ? "0x0000ff" : arg ); + mlt_properties_set_double( MLT_FILTER_PROPERTIES( this ), "variance", 0.15 ); this->process = filter_process; } return this; diff --git a/src/modules/vmfx/filter_chroma_hold.c b/src/modules/vmfx/filter_chroma_hold.c index 2992ceb..f3ede3f 100644 --- a/src/modules/vmfx/filter_chroma_hold.c +++ b/src/modules/vmfx/filter_chroma_hold.c @@ -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. @@ -58,18 +61,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; } } @@ -95,7 +93,7 @@ mlt_filter filter_chroma_hold_init( char *arg ) 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_double( MLT_FILTER_PROPERTIES( this ), "variance", 0.15 ); this->process = filter_process; } return this;