X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fsharpen.c;h=c95e69b83567cb29d3d216ffb002711aafbd813a;hb=0d8adc76dbf01e54ef043a07a623982a7fa9a426;hp=a1287fcb2423073174c9ece951e4f6332a5aaef7;hpb=7fbd1ca82e806a44e23510f35a70c4e87cde0998;p=vlc diff --git a/modules/video_filter/sharpen.c b/modules/video_filter/sharpen.c index a1287fcb24..c95e69b835 100644 --- a/modules/video_filter/sharpen.c +++ b/modules/video_filter/sharpen.c @@ -1,8 +1,8 @@ /***************************************************************************** * sharpen.c: Sharpen video filter ***************************************************************************** - * Copyright (C) 2003 the VideoLAN team - * $Id: sharpen.c 18062 2006-11-26 14:20:34Z zorglub $ + * Copyright (C) 2003-2007 the VideoLAN team + * $Id$ * * Author: Jérémy DEMEULE * Jean-Baptiste Kempf @@ -32,13 +32,17 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include "vlc_filter.h" +#include "filter_picture.h" #define SIG_TEXT N_("Sharpen strength (0-2)") #define SIG_LONGTEXT N_("Set the Sharpen strength, between 0 and 2. Defaults to 0.05.") @@ -59,18 +63,18 @@ static int SharpenCallback( vlc_object_t *, char const *, * Module descriptor *****************************************************************************/ vlc_module_begin(); - set_description( _("Augment contrast between contours.") ); - set_shortname( _("Sharpen video filter") ); + set_description( N_("Augment contrast between contours.") ); + set_shortname( N_("Sharpen video filter") ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); set_capability( "video filter2", 0 ); add_float_with_range( "sharpen-sigma", 0.05, 0.0, 2.0, NULL, - SIG_TEXT, SIG_LONGTEXT, VLC_FALSE ); + SIG_TEXT, SIG_LONGTEXT, false ); add_shortcut( "sharpen" ); set_callbacks( Create, Destroy ); vlc_module_end(); -static const char *ppsz_filter_options[] = { +static const char *const ppsz_filter_options[] = { "sigma", NULL }; @@ -84,6 +88,7 @@ static const char *ppsz_filter_options[] = { struct filter_sys_t { float f_sigma; + int tab_precalc[512]; }; /***************************************************************************** @@ -94,6 +99,16 @@ inline static int32_t clip( int32_t a ) return (a > 255) ? 255 : (a < 0) ? 0 : a; } +static void init_precalc_table(filter_sys_t *p_filter) +{ + float sigma = p_filter->f_sigma; + + for(int i = 0; i < 512; ++i) + { + p_filter->tab_precalc[i] = (i - 256) * sigma; + } +} + /***************************************************************************** * Create: allocates Sharpen video thread output method ***************************************************************************** @@ -106,10 +121,7 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } p_filter->pf_video_filter = Filter; @@ -121,6 +133,8 @@ static int Create( vlc_object_t *p_this ) var_AddCallback( p_filter, FILTER_PREFIX "sigma", SharpenCallback, p_filter->p_sys ); + init_precalc_table(p_filter->p_sys); + return VLC_SUCCESS; } @@ -158,12 +172,10 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) if( !p_filter ) return NULL; if( !p_filter->p_sys ) return NULL; - p_outpic = p_filter->pf_vout_buffer_new( p_filter ); + p_outpic = filter_NewPicture( p_filter ); if( !p_outpic ) { - msg_Warn( p_filter, "can't get output picture" ); - if( p_pic->pf_release ) - p_pic->pf_release( p_pic ); + picture_Release( p_pic ); return NULL; } @@ -173,8 +185,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) if( !p_src || !p_out ) { msg_Warn( p_filter, "can't get Y plane" ); - if( p_pic->pf_release ) - p_pic->pf_release( p_pic ); + picture_Release( p_pic ); return NULL; } @@ -207,39 +218,31 @@ 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 + 1] * v1); - p_out[i * i_src_pitch + j] = clip( p_src[i * i_src_pitch + j] + - (p_filter->p_sys->f_sigma * pix) ); + pix = pix >= 0 ? clip(pix) : -clip(pix * -1); + 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_libvlc->pf_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_filter->p_libvlc->pf_memcpy( p_outpic->p[V_PLANE].p_pixels, - p_pic->p[V_PLANE].p_pixels, - p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch ); - + 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->date = p_pic->date; - p_outpic->b_force = p_pic->b_force; - p_outpic->i_nb_fields = p_pic->i_nb_fields; - p_outpic->b_progressive = p_pic->b_progressive; - p_outpic->b_top_field_first = p_pic->b_top_field_first; + vlc_memcpy( p_outpic->p[V_PLANE].p_pixels, p_pic->p[V_PLANE].p_pixels, + p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch ); - if( p_pic->pf_release ) - p_pic->pf_release( p_pic ); - return p_outpic; + return CopyInfoAndRelease( p_outpic, p_pic ); } static int SharpenCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(oldval); 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 ) ); + init_precalc_table(p_sys); return VLC_SUCCESS; }