Commit c256e739 authored by Antoine Cellerier's avatar Antoine Cellerier

* Don't call var_Get every time we have an image to process and register the...

 * Don't call var_Get every time we have an image to process and register the variables as commands.
parent 88870d9b
...@@ -49,6 +49,9 @@ static int Create ( vlc_object_t * ); ...@@ -49,6 +49,9 @@ static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * ); static void Destroy ( vlc_object_t * );
static picture_t *Filter( filter_t *, picture_t * ); static picture_t *Filter( filter_t *, picture_t * );
static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval,
void *p_data );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -104,6 +107,12 @@ static const char *ppsz_filter_options[] = { ...@@ -104,6 +107,12 @@ static const char *ppsz_filter_options[] = {
*****************************************************************************/ *****************************************************************************/
struct filter_sys_t struct filter_sys_t
{ {
double f_contrast;
double f_brightness;
int i_hue;
double f_saturation;
double f_gamma;
vlc_bool_t b_brightness_threshold;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -114,6 +123,7 @@ struct filter_sys_t ...@@ -114,6 +123,7 @@ struct filter_sys_t
static int Create( vlc_object_t *p_this ) static int Create( vlc_object_t *p_this )
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
/* XXX: we might need to add/remove some FOURCCs ... */ /* XXX: we might need to add/remove some FOURCCs ... */
if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0')
...@@ -157,6 +167,7 @@ static int Create( vlc_object_t *p_this ) ...@@ -157,6 +167,7 @@ static int Create( vlc_object_t *p_this )
msg_Err( p_filter, "out of memory" ); msg_Err( p_filter, "out of memory" );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
p_sys = p_filter->p_sys;
p_filter->pf_video_filter = Filter; p_filter->pf_video_filter = Filter;
...@@ -165,18 +176,21 @@ static int Create( vlc_object_t *p_this ) ...@@ -165,18 +176,21 @@ static int Create( vlc_object_t *p_this )
config_ChainParse( p_filter, "", ppsz_filter_options, config_ChainParse( p_filter, "", ppsz_filter_options,
p_filter->p_cfg ); p_filter->p_cfg );
var_Create( p_filter, "contrast", p_sys->f_contrast = var_CreateGetFloatCommand( p_filter, "contrast" );
VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); p_sys->f_brightness = var_CreateGetFloatCommand( p_filter, "brightness" );
var_Create( p_filter, "brightness", p_sys->i_hue = var_CreateGetIntegerCommand( p_filter, "hue" );
VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); p_sys->f_saturation = var_CreateGetFloatCommand( p_filter, "saturation" );
var_Create( p_filter, "hue", p_sys->f_gamma = var_CreateGetFloatCommand( p_filter, "gamma" );
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); p_sys->b_brightness_threshold =
var_Create( p_filter, "saturation", var_CreateGetBoolCommand( p_filter, "brightness-threshold" );
VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
var_Create( p_filter, "gamma", var_AddCallback( p_filter, "contrast", AdjustCallback, p_sys );
VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
var_Create( p_filter, "brightness-threshold", var_AddCallback( p_filter, "hue", AdjustCallback, p_sys );
VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys );
var_AddCallback( p_filter, "gamma", AdjustCallback, p_sys );
var_AddCallback( p_filter, "brightness-threshold",
AdjustCallback, p_sys );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -214,7 +228,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -214,7 +228,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
int32_t i_cont, i_lum; int32_t i_cont, i_lum;
int i_sat, i_sin, i_cos, i_x, i_y; int i_sat, i_sin, i_cos, i_x, i_y;
int i; int i;
vlc_value_t val;
filter_sys_t *p_sys = p_filter->p_sys;
if( !p_pic ) return NULL; if( !p_pic ) return NULL;
...@@ -228,18 +243,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -228,18 +243,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
} }
/* Getvariables */ /* Getvariables */
var_Get( p_filter, "contrast", &val ); i_cont = (int)( p_sys->f_contrast * 255 );
i_cont = (int) ( val.f_float * 255 ); i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
var_Get( p_filter, "brightness", &val ); f_hue = (float)( p_sys->i_hue * M_PI / 180 );
i_lum = (int) (( val.f_float - 1.0 ) * 255 ); i_sat = (int)( p_sys->f_saturation * 256 );
var_Get( p_filter, "hue", &val ); f_gamma = 1.0 / p_sys->f_gamma;
f_hue = (float) ( val.i_int * M_PI / 180 ); b_thres = p_sys->b_brightness_threshold;
var_Get( p_filter, "saturation", &val );
i_sat = (int) (val.f_float * 256 );
var_Get( p_filter, "gamma", &val );
f_gamma = 1.0 / val.f_float;
var_Get( p_filter, "brightness-threshold", &val );
b_thres = (vlc_bool_t) ( val.b_bool );
/* /*
* Threshold mode drops out everything about luma, contrast and gamma. * Threshold mode drops out everything about luma, contrast and gamma.
...@@ -426,3 +435,26 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -426,3 +435,26 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
return p_outpic; return p_outpic;
} }
static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval,
void *p_data )
{
filter_sys_t *p_sys = (filter_sys_t *)p_data;
if( !strcmp( psz_var, "contrast" ) )
p_sys->f_contrast = newval.f_float;
else if( !strcmp( psz_var, "brightness" ) )
p_sys->f_brightness = newval.f_float;
else if( !strcmp( psz_var, "hue" ) )
p_sys->i_hue = newval.i_int;
else if( !strcmp( psz_var, "saturation" ) )
p_sys->f_saturation = newval.f_float;
else if( !strcmp( psz_var, "gamma" ) )
p_sys->f_gamma = newval.f_float;
else if( !strcmp( psz_var, "brightness-threshold" ) )
p_sys->b_brightness_threshold = newval.b_bool;
else
return VLC_EGENERIC;
return VLC_SUCCESS;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment