X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fmotionblur.c;h=4dedc12dabde93986e8ac0d887c828c31dd282f6;hb=001e2bb351f6b386d540a05bd0b688934d1009b4;hp=4ff29f0fcdbce8d81f680cac422b271a2975d34c;hpb=4da4c94a41ad44ce34a76a63e4f89c2f1ea4619a;p=vlc diff --git a/modules/video_filter/motionblur.c b/modules/video_filter/motionblur.c index 4ff29f0fcd..4dedc12dab 100644 --- a/modules/video_filter/motionblur.c +++ b/modules/video_filter/motionblur.c @@ -1,346 +1,217 @@ /***************************************************************************** - * motion_blur.c : motion blur filter for vlc + * motionblur.c : motion blur filter for vlc ***************************************************************************** - * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN - * $Id: motionblur.c,v 1.6 2003/01/17 16:18:03 sam Exp $ + * Copyright (C) 2000, 2001, 2002, 2003 VLC authors and VideoLAN + * $Id$ * - * Authors: Sigmund Augdal + * 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., 59 Temple Place - Suite 330, Boston, MA 02111, 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 -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include "filter_common.h" +#include +#include +#include +#include +#include +#include "filter_picture.h" /***************************************************************************** * Local protypes *****************************************************************************/ -static int Create ( vlc_object_t * ); -static void Destroy ( vlc_object_t * ); - -static int Init ( vout_thread_t * ); -static void End ( vout_thread_t * ); -static void Render ( vout_thread_t *, picture_t * ); - -static void RenderBlur ( vout_thread_t *, picture_t *, picture_t *, picture_t * ); -static void CopyPicture ( vout_thread_t*, picture_t *, picture_t * ); - -static int SendEvents( vlc_object_t *, char const *, - vlc_value_t, vlc_value_t, void * ); +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 int MotionBlurCallback( vlc_object_t *, char const *, + vlc_value_t, vlc_value_t, void * ); /***************************************************************************** * Module descriptor *****************************************************************************/ -#define MODE_TEXT N_("Blur factor") -#define MODE_LONGTEXT N_("The degree of blurring from 1 to 127") +#define FACTOR_TEXT N_("Blur factor (1-127)") +#define FACTOR_LONGTEXT N_("The degree of blurring from 1 to 127.") -vlc_module_begin(); - add_category_hint( N_("Miscellaneous"), NULL ); - add_integer( "blur-factor", 80, NULL, MODE_TEXT, MODE_LONGTEXT ); - set_description( _("Motion blur filter") ); - set_capability( "video filter", 0 ); - set_callbacks( Create, Destroy ); -vlc_module_end(); +#define FILTER_PREFIX "blur-" -/***************************************************************************** - * vout_sys_t: Deinterlace video output method descriptor - ***************************************************************************** - * This structure is part of the video output thread descriptor. - * It describes the Deinterlace specific properties of an output thread. - *****************************************************************************/ -struct vout_sys_t -{ - int i_factor; /* Deinterlace mode */ - vlc_bool_t b_double_rate; /* Shall we double the framerate? */ +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, + FACTOR_TEXT, FACTOR_LONGTEXT, false ) - mtime_t last_date; - mtime_t next_date; + add_shortcut( "blur" ) - vout_thread_t *p_vout; - picture_t *p_lastpic; + set_callbacks( Create, Destroy ) +vlc_module_end () + +static const char *const ppsz_filter_options[] = { + "factor", NULL }; /***************************************************************************** - * Create: allocates Deinterlace video thread output method - ***************************************************************************** - * This function allocates and initializes a Deinterlace vout method. + * filter_sys_t *****************************************************************************/ -static int Create( vlc_object_t *p_this ) +struct filter_sys_t { - vout_thread_t *p_vout = (vout_thread_t *)p_this; - - /* Allocate structure */ - p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); - if( p_vout->p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); - return VLC_ENOMEM; - } - - p_vout->pf_init = Init; - p_vout->pf_end = End; - p_vout->pf_manage = NULL; - p_vout->pf_render = Render; - p_vout->pf_display = NULL; - - p_vout->p_sys->i_factor = config_GetInt( p_vout, "blur-factor" ); - p_vout->p_sys->b_double_rate = 0; - p_vout->p_sys->last_date = 0; - p_vout->p_sys->p_lastpic = NULL; - - return VLC_SUCCESS; -} + picture_t *p_tmp; + bool b_first; + atomic_int i_factor; +}; /***************************************************************************** - * Init: initialize Deinterlace video thread output method + * Create *****************************************************************************/ -static int Init( vout_thread_t *p_vout ) +static int Create( vlc_object_t *p_this ) { - int i_index; - picture_t *p_pic; - - I_OUTPUTPICTURES = 0; + filter_t *p_filter = (filter_t *)p_this; - /* Initialize the output structure, full of directbuffers since we want - * the decoder to output directly to our structures. */ - switch( p_vout->render.i_chroma ) - { - case VLC_FOURCC('I','4','2','0'): - case VLC_FOURCC('I','Y','U','V'): - case VLC_FOURCC('Y','V','1','2'): - case VLC_FOURCC('I','4','2','2'): - p_vout->output.i_chroma = p_vout->render.i_chroma; - p_vout->output.i_width = p_vout->render.i_width; - p_vout->output.i_height = p_vout->render.i_height; - p_vout->output.i_aspect = p_vout->render.i_aspect; - break; - - default: - return VLC_EGENERIC; /* unknown chroma */ - break; - } + 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; - msg_Dbg( p_vout, "spawning the real video output" ); + /* Allocate structure */ + p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); + if( p_filter->p_sys == NULL ) + return VLC_ENOMEM; - switch( p_vout->render.i_chroma ) + p_filter->p_sys->p_tmp = picture_NewFromFormat( &p_filter->fmt_in.video ); + if( !p_filter->p_sys->p_tmp ) { - case VLC_FOURCC('I','4','2','0'): - case VLC_FOURCC('I','Y','U','V'): - case VLC_FOURCC('Y','V','1','2'): - p_vout->p_sys->p_vout = vout_Create( p_vout, - p_vout->output.i_width, p_vout->output.i_height, - p_vout->output.i_chroma, p_vout->output.i_aspect ); - break; - default: - break; + free( p_filter->p_sys ); + return VLC_ENOMEM; } + p_filter->p_sys->b_first = true; - /* Everything failed */ - if( p_vout->p_sys->p_vout == NULL ) - { - msg_Err( p_vout, "cannot open vout, aborting" ); + p_filter->pf_video_filter = Filter; - return VLC_EGENERIC; - } + config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, + p_filter->p_cfg ); - ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES ); + 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 ); - ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); return VLC_SUCCESS; } /***************************************************************************** - * End: terminate Deinterlace video thread output method - *****************************************************************************/ -static void End( vout_thread_t *p_vout ) -{ - int i_index; - - /* Free the fake output buffers we allocated */ - for( i_index = I_OUTPUTPICTURES ; i_index ; ) - { - i_index--; - free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); - } -} - -/***************************************************************************** - * Destroy: destroy Deinterlace video thread output method - ***************************************************************************** - * Terminate an output method created by DeinterlaceCreateOutputMethod + * Destroy *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { - vout_thread_t *p_vout = (vout_thread_t *)p_this; + filter_t *p_filter = (filter_t *)p_this; - DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); - vout_Destroy( p_vout->p_sys->p_vout ); + var_DelCallback( p_filter, FILTER_PREFIX "factor", + MotionBlurCallback, p_filter->p_sys ); - free( p_vout->p_sys ); + picture_Release( p_filter->p_sys->p_tmp ); + free( p_filter->p_sys ); } /***************************************************************************** - * Render: displays previously rendered output - ***************************************************************************** - * This function send the currently rendered image to Deinterlace image, - * waits until it is displayed and switch the two rendering buffers, preparing - * next frame. + * Filter *****************************************************************************/ -static void Render ( vout_thread_t *p_vout, picture_t *p_pic ) +static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) { picture_t * p_outpic; - while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) - == NULL ) - { - if( p_vout->b_die || p_vout->b_error ) - { - return; - } - msleep( VOUT_OUTMEM_SLEEP ); - } - vout_DatePicture( p_vout, p_outpic, p_pic->date ); + filter_sys_t *p_sys = p_filter->p_sys; + + if( !p_pic ) return NULL; - if ( p_vout->p_sys->p_lastpic == NULL ) + p_outpic = filter_NewPicture( p_filter ); + if( !p_outpic ) { - /* Get a new picture */ - while( ( p_vout->p_sys->p_lastpic = - vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) - == NULL ) - { - if( p_vout->b_die || p_vout->b_error ) - { - return; - } - msleep( VOUT_OUTMEM_SLEEP ); - } - CopyPicture( p_vout, p_vout->p_sys->p_lastpic, p_pic ); - CopyPicture( p_vout, p_outpic, p_pic ); - vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); - return; + picture_Release( p_pic ); + return NULL; } - /* Get a new picture */ - RenderBlur( p_vout, p_vout->p_sys->p_lastpic, p_pic, p_outpic ); - vout_DestroyPicture( p_vout, p_vout->p_sys->p_lastpic ); - - - /* Get a new picture */ - while( ( p_vout->p_sys->p_lastpic = - vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) - == NULL ) + if( p_sys->b_first ) { - if( p_vout->b_die || p_vout->b_error ) - { - return; - } - msleep( VOUT_OUTMEM_SLEEP ); + picture_CopyPixels( p_sys->p_tmp, p_pic ); + p_sys->b_first = false; } - CopyPicture( p_vout, p_vout->p_sys->p_lastpic, p_outpic ); - vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); -} -/* FIXME: this is a verbatim copy from src/video_output/vout_pictures.c */ -/* XXX: the order is fucked up!! */ -static void CopyPicture( vout_thread_t * p_vout, - picture_t *p_dest, picture_t *p_src ) -{ - int i; + /* Get a new picture */ + RenderBlur( p_sys, p_pic, p_outpic ); - for( i = 0; i < p_src->i_planes ; i++ ) - { - if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch ) - { - /* There are margins, but with the same width : perfect ! */ - p_vout->p_vlc->pf_memcpy( - p_dest->p[i].p_pixels, p_src->p[i].p_pixels, - p_src->p[i].i_pitch * p_src->p[i].i_lines ); - } - else - { - /* We need to proceed line by line */ - uint8_t *p_in = p_src->p[i].p_pixels; - uint8_t *p_out = p_dest->p[i].p_pixels; - int i_line; + picture_CopyPixels( p_sys->p_tmp, p_outpic ); - for( i_line = p_src->p[i].i_lines; i_line--; ) - { - p_vout->p_vlc->pf_memcpy( p_out, p_in, - p_src->p[i].i_visible_pitch ); - p_in += p_src->p[i].i_pitch; - p_out += p_dest->p[i].i_pitch; - } - } - } + return CopyInfoAndRelease( p_outpic, p_pic ); } /***************************************************************************** * RenderBlur: renders a blurred picture *****************************************************************************/ -static void RenderBlur( vout_thread_t *p_vout, picture_t *p_oldpic, - picture_t *p_newpic, picture_t *p_outpic ) +static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, + picture_t *p_outpic ) { int i_plane; - int i_oldfactor = p_vout->p_sys->i_factor; - int i_newfactor = 128 - p_vout->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_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_oldpic->p[i_plane].p_pixels; - p_out_end = p_out + p_outpic->p[i_plane].i_pitch * - p_outpic->p[i_plane].i_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 + p_outpic->p[i_plane].i_visible_pitch; + p_out_line_end = p_out + i_visible_pitch; while ( p_out < p_out_line_end ) { *p_out++ = (((*p_old++) * i_oldfactor) + ((*p_new++) * i_newfactor)) >> 7; - -// *p_out++ = (*p_old++ >> 1) + (*p_new++ >> 1); } - p_old += p_oldpic->p[i_plane].i_pitch - - p_oldpic->p[i_plane].i_visible_pitch; - p_new += p_newpic->p[i_plane].i_pitch - - p_newpic->p[i_plane].i_visible_pitch; - p_out += p_outpic->p[i_plane].i_pitch - - p_outpic->p[i_plane].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; } } } -/***************************************************************************** - * SendEvents: forward mouse and keyboard events to the parent p_vout - *****************************************************************************/ -static int SendEvents( vlc_object_t *p_this, char const *psz_var, - vlc_value_t oldval, vlc_value_t newval, void *p_data ) +static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var, + vlc_value_t oldval, vlc_value_t newval, + void *p_data ) { - var_Set( (vlc_object_t *)p_data, psz_var, newval ); + 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; } -