X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fgradient.c;h=604a3ac1468e9724f2343e269ec7dc471b84d284;hb=0f00164eb903cee76c89575ed26117332ed1ee99;hp=0dd5f637927a7d0c78f87137c3bb35111bf1edf7;hpb=9ce72981b5df1177e9e1b701698e992ca4437b0e;p=vlc diff --git a/modules/video_filter/gradient.c b/modules/video_filter/gradient.c index 0dd5f63792..604a3ac146 100644 --- a/modules/video_filter/gradient.c +++ b/modules/video_filter/gradient.c @@ -25,11 +25,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include #include /* sin(), cos() */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -45,6 +47,9 @@ static int Create ( vlc_object_t * ); static void Destroy ( vlc_object_t * ); static picture_t *Filter( filter_t *, picture_t * ); +static int GradientCallback( vlc_object_t *, char const *, + vlc_value_t, vlc_value_t, + void * ); static void FilterGradient( filter_t *, picture_t *, picture_t * ); static void FilterEdge ( filter_t *, picture_t *, picture_t * ); @@ -64,8 +69,8 @@ static void FilterHough ( filter_t *, picture_t *, picture_t * ); #define CARTOON_LONGTEXT N_("Apply cartoon effect. It is only used by " \ "\"gradient\" and \"edge\".") -static char *mode_list[] = { "gradient", "edge", "hough" }; -static char *mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") }; +static const char *mode_list[] = { "gradient", "edge", "hough" }; +static const char *mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") }; #define FILTER_PREFIX "gradient-" @@ -140,14 +145,8 @@ static int Create( vlc_object_t *p_this ) config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, p_filter->p_cfg ); - var_Create( p_filter, FILTER_PREFIX "mode", - VLC_VAR_STRING | VLC_VAR_DOINHERIT ); - var_Create( p_filter, FILTER_PREFIX "type", - VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); - var_Create( p_filter, FILTER_PREFIX "cartoon", - VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); - - if( !(psz_method = var_GetString( p_filter, FILTER_PREFIX "mode" )) ) + if( !(psz_method = + var_CreateGetNonEmptyStringCommand( p_filter, FILTER_PREFIX "mode" )) ) { msg_Err( p_filter, "configuration variable " FILTER_PREFIX "mode empty" ); @@ -169,16 +168,23 @@ static int Create( vlc_object_t *p_this ) } else { - msg_Err( p_filter, "no valid gradient mode provided" ); + msg_Err( p_filter, "no valid gradient mode provided (%s)", psz_method ); p_filter->p_sys->i_mode = GRADIENT; } } free( psz_method ); p_filter->p_sys->i_gradient_type = - var_GetInteger( p_filter, FILTER_PREFIX "type" ); + var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "type" ); p_filter->p_sys->b_cartoon = - var_GetInteger( p_filter, FILTER_PREFIX "cartoon" ); + var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" ); + + var_AddCallback( p_filter, FILTER_PREFIX "mode", + GradientCallback, p_filter->p_sys ); + var_AddCallback( p_filter, FILTER_PREFIX "type", + GradientCallback, p_filter->p_sys ); + var_AddCallback( p_filter, FILTER_PREFIX "cartoon", + GradientCallback, p_filter->p_sys ); p_filter->p_sys->p_buf32 = NULL; p_filter->p_sys->p_buf32_bis = NULL; @@ -256,7 +262,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) return p_outpic; } - /***************************************************************************** * Gaussian Convolution ***************************************************************************** @@ -418,10 +423,7 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic, else { FOR - if( a>>8 ) - p_outpix[y*i_dst_pitch+x] = 255; - else - p_outpix[y*i_dst_pitch+x] = (uint8_t)a; + p_outpix[y*i_dst_pitch+x] = clip_uint8_vlc( a ); }} } } @@ -734,7 +736,45 @@ static void FilterHough( filter_t *p_filter, picture_t *p_inpic, } } - if( p_hough ) free( p_hough ); - if( p_smooth ) free( p_smooth ); + free( p_hough ); + free( p_smooth ); } #undef p_pre_hough + + +static int GradientCallback( vlc_object_t *p_this, char const *psz_var, + vlc_value_t oldval, vlc_value_t newval, + void *p_data ) +{ + VLC_UNUSED(oldval); + filter_sys_t *p_sys = (filter_sys_t *)p_data; + if( !strcmp( psz_var, FILTER_PREFIX "mode" ) ) + { + if( !strcmp( newval.psz_string, "gradient" ) ) + { + p_sys->i_mode = GRADIENT; + } + else if( !strcmp( newval.psz_string, "edge" ) ) + { + p_sys->i_mode = EDGE; + } + else if( !strcmp( newval.psz_string, "hough" ) ) + { + p_sys->i_mode = HOUGH; + } + else + { + msg_Err( p_this, "no valid gradient mode provided (%s)", newval.psz_string ); + p_sys->i_mode = GRADIENT; + } + } + else if( !strcmp( psz_var, FILTER_PREFIX "type" ) ) + { + p_sys->i_gradient_type = newval.i_int; + } + else if( !strcmp( psz_var, FILTER_PREFIX "cartoon" ) ) + { + p_sys->b_cartoon = newval.b_bool; + } + return VLC_SUCCESS; +}