/*****************************************************************************
* gradient.c : Gradient and edge detection video effects plugin for vlc
*****************************************************************************
- * Copyright (C) 2000-2006 the VideoLAN team
+ * Copyright (C) 2000-2008 VLC authors and VideoLAN
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Antoine Cellerier <dionoea -at- videolan -dot- org>
*
- * 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 <math.h> /* sin(), cos() */
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <math.h> /* sin(), cos() */
+
+#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_sout.h>
-#include <vlc_vout.h>
-#include "vlc_filter.h"
+#include <vlc_filter.h>
+#include "filter_picture.h"
enum { GRADIENT, EDGE, HOUGH };
#define CARTOON_LONGTEXT N_("Apply cartoon effect. It is only used by " \
"\"gradient\" and \"edge\".")
+#define GRADIENT_HELP N_("Apply color gradient or edge detection effects")
+
static const char *const mode_list[] = { "gradient", "edge", "hough" };
static const char *const mode_list_text[] = { N_("Gradient"), N_("Edge"), N_("Hough") };
#define FILTER_PREFIX "gradient-"
-vlc_module_begin();
- set_description( N_("Gradient video filter") );
- set_shortname( N_( "Gradient" ));
- set_capability( "video filter2", 0 );
- set_category( CAT_VIDEO );
- set_subcategory( SUBCAT_VIDEO_VFILTER );
+vlc_module_begin ()
+ set_description( N_("Gradient video filter") )
+ set_shortname( N_( "Gradient" ))
+ set_help(GRADIENT_HELP)
+ set_capability( "video filter2", 0 )
+ set_category( CAT_VIDEO )
+ set_subcategory( SUBCAT_VIDEO_VFILTER )
- add_string( FILTER_PREFIX "mode", "gradient", NULL,
- MODE_TEXT, MODE_LONGTEXT, false );
- change_string_list( mode_list, mode_list_text, 0 );
+ add_string( FILTER_PREFIX "mode", "gradient",
+ MODE_TEXT, MODE_LONGTEXT, false )
+ change_string_list( mode_list, mode_list_text )
- add_integer_with_range( FILTER_PREFIX "type", 0, 0, 1, NULL,
- GRADIENT_TEXT, GRADIENT_LONGTEXT, false );
- add_bool( FILTER_PREFIX "cartoon", 1, NULL,
- CARTOON_TEXT, CARTOON_LONGTEXT, false );
+ add_integer_with_range( FILTER_PREFIX "type", 0, 0, 1,
+ GRADIENT_TEXT, GRADIENT_LONGTEXT, false )
+ add_bool( FILTER_PREFIX "cartoon", true,
+ CARTOON_TEXT, CARTOON_LONGTEXT, false )
- add_shortcut( "gradient" );
- set_callbacks( Create, Destroy );
-vlc_module_end();
+ add_shortcut( "gradient" )
+ set_callbacks( Create, Destroy )
+vlc_module_end ()
static const char *const ppsz_filter_options[] = {
"mode", "type", "cartoon", NULL
};
/*****************************************************************************
- * vout_sys_t: Distort video output method descriptor
+ * filter_sys_t: Distort video output method descriptor
*****************************************************************************
* This structure is part of the video output thread descriptor.
* It describes the Distort specific properties of an output thread.
*****************************************************************************/
struct filter_sys_t
{
+ vlc_mutex_t lock;
int i_mode;
/* For the gradient mode */
filter_t *p_filter = (filter_t *)p_this;
char *psz_method;
+ switch( p_filter->fmt_in.video.i_chroma )
+ {
+ CASE_PLANAR_YUV
+ break;
+
+ default:
+ msg_Err( p_filter, "Unsupported input chroma (%4.4s)",
+ (char*)&(p_filter->fmt_in.video.i_chroma) );
+ return VLC_EGENERIC;
+ }
+
/* 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;
p_filter->p_sys->b_cartoon =
var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" );
+ vlc_mutex_init( &p_filter->p_sys->lock );
var_AddCallback( p_filter, FILTER_PREFIX "mode",
GradientCallback, p_filter->p_sys );
var_AddCallback( p_filter, FILTER_PREFIX "type",
static void Destroy( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
-
- free( p_filter->p_sys->p_buf32 );
- free( p_filter->p_sys->p_buf32_bis );
- free( p_filter->p_sys->p_buf8 );
- free( p_filter->p_sys->p_pre_hough );
-
- free( p_filter->p_sys );
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ var_DelCallback( p_filter, FILTER_PREFIX "mode",
+ GradientCallback, p_sys );
+ var_DelCallback( p_filter, FILTER_PREFIX "type",
+ GradientCallback, p_sys );
+ var_DelCallback( p_filter, FILTER_PREFIX "cartoon",
+ GradientCallback, p_sys );
+ vlc_mutex_destroy( &p_sys->lock );
+
+ free( p_sys->p_buf32 );
+ free( p_sys->p_buf32_bis );
+ free( p_sys->p_buf8 );
+ free( p_sys->p_pre_hough );
+
+ free( p_sys );
}
/*****************************************************************************
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" );
- if( p_pic->pf_release )
- p_pic->pf_release( p_pic );
+ picture_Release( p_pic );
return NULL;
}
+ vlc_mutex_lock( &p_filter->p_sys->lock );
switch( p_filter->p_sys->i_mode )
{
case EDGE:
default:
break;
}
+ vlc_mutex_unlock( &p_filter->p_sys->lock );
- 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;
-
- if( p_pic->pf_release )
- p_pic->pf_release( p_pic );
-
- return p_outpic;
+ return CopyInfoAndRelease( p_outpic, p_pic );
}
/*****************************************************************************
if( p_filter->p_sys->b_cartoon )
{
- vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
- p_inpic->p[U_PLANE].p_pixels,
- p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
- vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
- p_inpic->p[V_PLANE].p_pixels,
- p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
+ plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
+ plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
}
else
{
- vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
+ memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
- vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
+ memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
}
if( p_filter->p_sys->b_cartoon )
{
- vlc_memcpy( p_outpic->p[U_PLANE].p_pixels,
- p_inpic->p[U_PLANE].p_pixels,
- p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
- vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
- p_inpic->p[V_PLANE].p_pixels,
- p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
+ plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
+ plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
}
else
{
- vlc_memset( p_outpic->p[Y_PLANE].p_pixels, 0xff,
+ memset( p_outpic->p[Y_PLANE].p_pixels, 0xff,
p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
- vlc_memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
+ memset( p_outpic->p[U_PLANE].p_pixels, 0x80,
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
- vlc_memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
+ memset( p_outpic->p[V_PLANE].p_pixels, 0x80,
p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
}
double d_sin;
double d_cos;
uint32_t *p_smooth;
+
int *p_hough = malloc( i_diag * i_nb_steps * sizeof(int) );
if( ! p_hough ) return;
+
p_smooth = (uint32_t *)malloc( i_num_lines*i_src_visible*sizeof(uint32_t));
- if( !p_smooth ) return;
+ if( !p_smooth )
+ {
+ free( p_hough );
+ return;
+ }
if( ! p_pre_hough )
{
msg_Dbg(p_filter, "Starting precalculation");
p_pre_hough = malloc( i_num_lines*i_src_visible*i_nb_steps*sizeof(int));
- if( ! p_pre_hough ) return;
+ if( ! p_pre_hough )
+ {
+ free( p_smooth );
+ free( p_hough );
+ return;
+ }
for( i = 0 ; i < i_nb_steps ; i++)
{
d_sin = sin(d_step * i);
msg_Dbg(p_filter, "Precalculation done");
}
- vlc_memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) );
+ memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) );
- vlc_memcpy(
- p_outpic->p[Y_PLANE].p_pixels, p_inpic->p[Y_PLANE].p_pixels,
- p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
- vlc_memcpy(
- p_outpic->p[U_PLANE].p_pixels, p_inpic->p[U_PLANE].p_pixels,
- p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
- vlc_memcpy(
- p_outpic->p[V_PLANE].p_pixels, p_inpic->p[V_PLANE].p_pixels,
- p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
+ plane_CopyPixels( &p_outpic->p[Y_PLANE], &p_inpic->p[Y_PLANE] );
+ plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
+ plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
GaussianConvolution( p_inpic, p_smooth );
{
VLC_UNUSED(oldval);
filter_sys_t *p_sys = (filter_sys_t *)p_data;
+
+ vlc_mutex_lock( &p_sys->lock );
if( !strcmp( psz_var, FILTER_PREFIX "mode" ) )
{
if( !strcmp( newval.psz_string, "gradient" ) )
{
p_sys->b_cartoon = newval.b_bool;
}
+ vlc_mutex_unlock( &p_sys->lock );
+
return VLC_SUCCESS;
}