Commit 5e2bfc33 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Sharpen: thread safety and don't retain useless value

parent 0925032f
...@@ -87,7 +87,7 @@ static const char *const ppsz_filter_options[] = { ...@@ -87,7 +87,7 @@ static const char *const ppsz_filter_options[] = {
struct filter_sys_t struct filter_sys_t
{ {
float f_sigma; vlc_mutex_t lock;
int tab_precalc[512]; int tab_precalc[512];
}; };
...@@ -99,10 +99,8 @@ inline static int32_t clip( int32_t a ) ...@@ -99,10 +99,8 @@ inline static int32_t clip( int32_t a )
return (a > 255) ? 255 : (a < 0) ? 0 : a; return (a > 255) ? 255 : (a < 0) ? 0 : a;
} }
static void init_precalc_table(filter_sys_t *p_filter) static void init_precalc_table(filter_sys_t *p_filter, float sigma)
{ {
float sigma = p_filter->f_sigma;
for(int i = 0; i < 512; ++i) for(int i = 0; i < 512; ++i)
{ {
p_filter->tab_precalc[i] = (i - 256) * sigma; p_filter->tab_precalc[i] = (i - 256) * sigma;
...@@ -128,13 +126,13 @@ static int Create( vlc_object_t *p_this ) ...@@ -128,13 +126,13 @@ static int Create( vlc_object_t *p_this )
config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
p_filter->p_cfg ); p_filter->p_cfg );
p_filter->p_sys->f_sigma = float sigma = var_CreateGetFloatCommand( p_filter, FILTER_PREFIX "sigma" );
var_CreateGetFloatCommand( p_filter, FILTER_PREFIX "sigma" ); init_precalc_table(p_filter->p_sys, sigma);
vlc_mutex_init( &p_filter->p_sys->lock );
var_AddCallback( p_filter, FILTER_PREFIX "sigma", var_AddCallback( p_filter, FILTER_PREFIX "sigma",
SharpenCallback, p_filter->p_sys ); SharpenCallback, p_filter->p_sys );
init_precalc_table(p_filter->p_sys);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -147,9 +145,11 @@ static int Create( vlc_object_t *p_this ) ...@@ -147,9 +145,11 @@ static int Create( vlc_object_t *p_this )
static void Destroy( vlc_object_t *p_this ) static void Destroy( vlc_object_t *p_this )
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
var_DelCallback( p_filter, FILTER_PREFIX "sigma", filter_sys_t *p_sys = p_filter->p_sys;
SharpenCallback, p_filter->p_sys );
free( p_filter->p_sys ); var_DelCallback( p_filter, FILTER_PREFIX "sigma", SharpenCallback, p_sys );
vlc_mutex_destroy( &p_sys->lock );
free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -185,6 +185,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -185,6 +185,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
i_src_pitch = p_pic->p[Y_PLANE].i_visible_pitch; i_src_pitch = p_pic->p[Y_PLANE].i_visible_pitch;
/* perform convolution only on Y plane. Avoid border line. */ /* perform convolution only on Y plane. Avoid border line. */
vlc_mutex_lock( &p_filter->p_sys->lock );
for( i = 0; i < p_pic->p[Y_PLANE].i_visible_lines; i++ ) for( i = 0; i < p_pic->p[Y_PLANE].i_visible_lines; i++ )
{ {
if( (i == 0) || (i == p_pic->p[Y_PLANE].i_visible_lines - 1) ) if( (i == 0) || (i == p_pic->p[Y_PLANE].i_visible_lines - 1) )
...@@ -211,12 +212,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -211,12 +212,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
(p_src[(i + 1) * i_src_pitch + j ] * v1) + (p_src[(i + 1) * i_src_pitch + j ] * v1) +
(p_src[(i + 1) * i_src_pitch + j + 1] * v1); (p_src[(i + 1) * i_src_pitch + j + 1] * v1);
pix = pix >= 0 ? clip(pix) : -clip(pix * -1); pix = pix >= 0 ? clip(pix) : -clip(pix * -1);
p_out[i * i_src_pitch + j] = clip( p_src[i * i_src_pitch + j] + p_out[i * i_src_pitch + j] = clip( p_src[i * i_src_pitch + j] +
p_filter->p_sys->tab_precalc[pix + 256] ); p_filter->p_sys->tab_precalc[pix + 256] );
} }
} }
vlc_mutex_unlock( &p_filter->p_sys->lock );
vlc_memcpy( p_outpic->p[U_PLANE].p_pixels, p_pic->p[U_PLANE].p_pixels, vlc_memcpy( p_outpic->p[U_PLANE].p_pixels, p_pic->p[U_PLANE].p_pixels,
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch ); p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
...@@ -232,10 +233,11 @@ static int SharpenCallback( vlc_object_t *p_this, char const *psz_var, ...@@ -232,10 +233,11 @@ static int SharpenCallback( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *p_data ) void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
filter_sys_t *p_sys = (filter_sys_t *)p_data; filter_sys_t *p_sys = (filter_sys_t *)p_data;
if( !strcmp( psz_var, FILTER_PREFIX "sigma" ) )
p_sys->f_sigma = __MIN( 2., __MAX( 0., newval.f_float ) ); vlc_mutex_lock( &p_sys->lock );
init_precalc_table(p_sys); init_precalc_table(p_sys, __MIN( 2., __MAX( 0., newval.f_float ) ));
vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; 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