X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fmotionblur.c;h=4dedc12dabde93986e8ac0d887c828c31dd282f6;hb=001e2bb351f6b386d540a05bd0b688934d1009b4;hp=a92e46b31cc6b0f7ef0f8a59fd27548b56deef6f;hpb=93236cd63cf1c8dde138281bef097aee8976f2db;p=vlc diff --git a/modules/video_filter/motionblur.c b/modules/video_filter/motionblur.c index a92e46b31c..4dedc12dab 100644 --- a/modules/video_filter/motionblur.c +++ b/modules/video_filter/motionblur.c @@ -1,37 +1,41 @@ /***************************************************************************** - * motion_blur.c : motion blur filter for vlc + * motionblur.c : motion blur filter for vlc ***************************************************************************** - * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team + * Copyright (C) 2000, 2001, 2002, 2003 VLC authors and VideoLAN * $Id$ * * Authors: Sigmund Augdal Helberg * Antoine Cellerier * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include -#include #include +#include +#include "filter_picture.h" /***************************************************************************** * Local protypes @@ -40,7 +44,8 @@ static int Create ( vlc_object_t * ); static void Destroy ( vlc_object_t * ); static picture_t *Filter ( filter_t *, picture_t * ); static void RenderBlur ( filter_sys_t *, picture_t *, picture_t * ); -static void Copy ( filter_t *, uint8_t **, picture_t * ); +static int MotionBlurCallback( vlc_object_t *, char const *, + vlc_value_t, vlc_value_t, void * ); /***************************************************************************** * Module descriptor @@ -48,30 +53,25 @@ static void Copy ( filter_t *, uint8_t **, picture_t * ); #define FACTOR_TEXT N_("Blur factor (1-127)") #define FACTOR_LONGTEXT N_("The degree of blurring from 1 to 127.") -#define PERSISTANT_TEXT N_("Keep inifinte memory of past images") -#define PERSISTANT_LONGTEXT N_("Use \"Result = ( new image * ( 128 - factor ) + factor * old result ) / 128\" instead of \"Result = ( new image * ( 128 - factor ) + factor * old image ) / 128\".") - #define FILTER_PREFIX "blur-" -vlc_module_begin(); - set_shortname( _("Motion blur") ); - set_description( _("Motion blur filter") ); - set_capability( "video filter2", 0 ); - set_category( CAT_VIDEO ); - set_subcategory( SUBCAT_VIDEO_VFILTER ); +vlc_module_begin () + set_shortname( N_("Motion blur") ) + set_description( N_("Motion blur filter") ) + set_capability( "video filter2", 0 ) + set_category( CAT_VIDEO ) + set_subcategory( SUBCAT_VIDEO_VFILTER ) - add_integer_with_range( FILTER_PREFIX "factor", 80, 1, 127, NULL, - FACTOR_TEXT, FACTOR_LONGTEXT, VLC_FALSE ); - add_bool( FILTER_PREFIX "persistant", 0, NULL, PERSISTANT_TEXT, - PERSISTANT_LONGTEXT, VLC_FALSE ); + add_integer_with_range( FILTER_PREFIX "factor", 80, 1, 127, + FACTOR_TEXT, FACTOR_LONGTEXT, false ) - add_shortcut( "blur" ); + add_shortcut( "blur" ) - set_callbacks( Create, Destroy ); -vlc_module_end(); + set_callbacks( Create, Destroy ) +vlc_module_end () -static const char *ppsz_filter_options[] = { - "factor", "persistant", NULL +static const char *const ppsz_filter_options[] = { + "factor", NULL }; /***************************************************************************** @@ -79,11 +79,9 @@ static const char *ppsz_filter_options[] = { *****************************************************************************/ struct filter_sys_t { - int i_factor; - vlc_bool_t b_persistant; - - uint8_t **pp_planes; - int i_planes; + picture_t *p_tmp; + bool b_first; + atomic_int i_factor; }; /***************************************************************************** @@ -93,30 +91,34 @@ static int Create( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; + const vlc_chroma_description_t *p_chroma = + vlc_fourcc_GetChromaDescription( p_filter->fmt_in.video.i_chroma ); + if( p_chroma == NULL || p_chroma->plane_count == 0 ) + return VLC_EGENERIC; + /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) + return VLC_ENOMEM; + + p_filter->p_sys->p_tmp = picture_NewFromFormat( &p_filter->fmt_in.video ); + if( !p_filter->p_sys->p_tmp ) { - msg_Err( p_filter, "out of memory" ); + free( p_filter->p_sys ); return VLC_ENOMEM; } + p_filter->p_sys->b_first = true; p_filter->pf_video_filter = Filter; config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, p_filter->p_cfg ); - var_Create( p_filter, FILTER_PREFIX "factor", - VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); - p_filter->p_sys->i_factor = - var_GetInteger( p_filter, FILTER_PREFIX "factor" ); - var_Create( p_filter, FILTER_PREFIX "persistant", - VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); - p_filter->p_sys->b_persistant = - var_GetBool( p_filter, FILTER_PREFIX "persistant" ); + atomic_init( &p_filter->p_sys->i_factor, + var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "factor" ) ); + var_AddCallback( p_filter, FILTER_PREFIX "factor", + MotionBlurCallback, p_filter->p_sys ); - p_filter->p_sys->pp_planes = NULL; - p_filter->p_sys->i_planes = 0; return VLC_SUCCESS; } @@ -128,23 +130,13 @@ static void Destroy( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; - while( p_filter->p_sys->i_planes-- ) - free( p_filter->p_sys->pp_planes[p_filter->p_sys->i_planes] ); - free( p_filter->p_sys->pp_planes ); + var_DelCallback( p_filter, FILTER_PREFIX "factor", + MotionBlurCallback, p_filter->p_sys ); + + picture_Release( p_filter->p_sys->p_tmp ); free( p_filter->p_sys ); } -#define RELEASE( pic ) \ - if( pic ->pf_release ) \ - pic ->pf_release( pic ); - -#define INITPIC( dst, src ) \ - dst ->date = src ->date; \ - dst ->b_force = src ->b_force; \ - dst ->i_nb_fields = src ->i_nb_fields; \ - dst ->b_progressive = src->b_progressive; \ - dst ->b_top_field_first = src ->b_top_field_first; - /***************************************************************************** * Filter *****************************************************************************/ @@ -155,36 +147,25 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) if( !p_pic ) 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" ); - RELEASE( p_pic ); + picture_Release( p_pic ); return NULL; } - INITPIC( p_outpic, p_pic ); - if( !p_sys->pp_planes ) + if( p_sys->b_first ) { - /* initialise our picture buffer */ - int i_plane; - p_sys->i_planes = p_pic->i_planes; - p_sys->pp_planes = - (uint8_t**)malloc( p_sys->i_planes * sizeof( uint8_t * ) ); - for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) - { - p_sys->pp_planes[i_plane] = (uint8_t*)malloc( - p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines ); - } - Copy( p_filter, p_sys->pp_planes, p_pic ); + picture_CopyPixels( p_sys->p_tmp, p_pic ); + p_sys->b_first = false; } /* Get a new picture */ RenderBlur( p_sys, p_pic, p_outpic ); - Copy( p_filter, p_sys->pp_planes, p_sys->b_persistant ? p_outpic : p_pic ); - RELEASE( p_pic ); - return p_outpic; + picture_CopyPixels( p_sys->p_tmp, p_outpic ); + + return CopyInfoAndRelease( p_outpic, p_pic ); } /***************************************************************************** @@ -194,19 +175,19 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, picture_t *p_outpic ) { int i_plane; - int i_oldfactor = p_sys->i_factor; + const int i_oldfactor = atomic_load( &p_sys->i_factor ); int i_newfactor = 128 - i_oldfactor; + for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ ) { uint8_t *p_old, *p_new, *p_out, *p_out_end, *p_out_line_end; - const int i_pitch = p_outpic->p[i_plane].i_pitch; const int i_visible_pitch = p_outpic->p[i_plane].i_visible_pitch; const int i_visible_lines = p_outpic->p[i_plane].i_visible_lines; p_out = p_outpic->p[i_plane].p_pixels; p_new = p_newpic->p[i_plane].p_pixels; - p_old = p_sys->pp_planes[i_plane]; - p_out_end = p_out + i_pitch * i_visible_lines; + p_old = p_sys->p_tmp->p[i_plane].p_pixels; + p_out_end = p_out + p_outpic->p[i_plane].i_pitch * i_visible_lines; while ( p_out < p_out_end ) { p_out_line_end = p_out + i_visible_pitch; @@ -217,20 +198,20 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, ((*p_new++) * i_newfactor)) >> 7; } - p_old += i_pitch - i_visible_pitch; - p_new += i_pitch - i_visible_pitch; - p_out += i_pitch - i_visible_pitch; + p_old += p_sys->p_tmp->p[i_plane].i_pitch - i_visible_pitch; + p_new += p_newpic->p[i_plane].i_pitch - i_visible_pitch; + p_out += p_outpic->p[i_plane].i_pitch - i_visible_pitch; } } } -static void Copy( filter_t *p_filter, uint8_t **pp_planes, picture_t *p_pic ) +static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var, + vlc_value_t oldval, vlc_value_t newval, + void *p_data ) { - int i_plane; - for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) - { - p_filter->p_libvlc->pf_memcpy( - p_filter->p_sys->pp_planes[i_plane], p_pic->p[i_plane].p_pixels, - p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines ); - } + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval); + filter_sys_t *p_sys = (filter_sys_t *)p_data; + + atomic_store( &p_sys->i_factor, VLC_CLIP( newval.i_int, 1, 127 ) ); + return VLC_SUCCESS; }