/*****************************************************************************
* colorthres.c: Theshold color based on similarity to reference color
*****************************************************************************
- * Copyright (C) 2000-2006 the VideoLAN team
+ * Copyright (C) 2000-2009 the VideoLAN team
* $Id$
*
* Authors: Sigmund Augdal <dnumgis@videolan.org>
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <errno.h>
-#include <math.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <errno.h>
+#include <math.h>
+
+#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"
/*****************************************************************************
#define CFG_PREFIX "colorthres-"
-vlc_module_begin();
- set_description( N_("Color threshold filter") );
- set_shortname( N_("Color threshold" ));
- set_category( CAT_VIDEO );
- set_subcategory( SUBCAT_VIDEO_VFILTER );
- set_capability( "video filter2", 0 );
+vlc_module_begin ()
+ set_description( N_("Color threshold filter") )
+ set_shortname( N_("Color threshold" ))
+ set_category( CAT_VIDEO )
+ set_subcategory( SUBCAT_VIDEO_VFILTER )
+ set_capability( "video filter2", 0 )
add_integer( CFG_PREFIX "color", 0x00FF0000, NULL, COLOR_TEXT,
- COLOR_LONGTEXT, false );
- change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
+ COLOR_LONGTEXT, false )
+ change_integer_list( pi_color_values, ppsz_color_descriptions, NULL )
add_integer( CFG_PREFIX "saturationthres", 20, NULL,
- _("Saturaton threshold"), "", false );
+ N_("Saturaton threshold"), "", false )
add_integer( CFG_PREFIX "similaritythres", 15, NULL,
- _("Similarity threshold"), "", false );
- set_callbacks( Create, Destroy );
-vlc_module_end();
+ N_("Similarity threshold"), "", false )
+ set_callbacks( Create, Destroy )
+vlc_module_end ()
static const char *const ppsz_filter_options[] = {
"color", "saturationthes", "similaritythres", NULL
};
+/*****************************************************************************
+ * callback prototypes
+ *****************************************************************************/
+static int FilterCallback( vlc_object_t *, char const *,
+ vlc_value_t, vlc_value_t, void * );
+
+
/*****************************************************************************
* filter_sys_t: adjust filter method descriptor
*****************************************************************************/
struct filter_sys_t
{
+ int i_simthres;
+ int i_satthres;
+ int i_color;
+ vlc_mutex_t lock;
};
/*****************************************************************************
static int Create( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
+ filter_sys_t *p_sys;
switch( p_filter->fmt_in.video.i_chroma )
{
return VLC_EGENERIC;
}
- config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
- p_filter->p_cfg );
- var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "color" );
- var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "similaritythres" );
- var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "saturationthres" );
-
/* Allocate structure */
- p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
+ p_sys = 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;
- }
+
+ config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
+ p_filter->p_cfg );
+ p_sys->i_color = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "color" );
+ p_sys->i_simthres = var_CreateGetIntegerCommand( p_filter,
+ CFG_PREFIX "similaritythres" );
+ p_sys->i_satthres = var_CreateGetIntegerCommand( p_filter,
+ CFG_PREFIX "saturationthres" );
+
+ vlc_mutex_init( &p_sys->lock );
+
+ var_AddCallback( p_filter, CFG_PREFIX "color", FilterCallback, NULL );
+ var_AddCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, NULL );
+ var_AddCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, NULL );
p_filter->pf_video_filter = Filter;
static void Destroy( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
+
+ var_DelCallback( p_filter, CFG_PREFIX "color", FilterCallback, NULL );
+ var_DelCallback( p_filter, CFG_PREFIX "similaritythres", FilterCallback, NULL );
+ var_DelCallback( p_filter, CFG_PREFIX "saturationthres", FilterCallback, NULL );
+
+ vlc_mutex_destroy( &p_filter->p_sys->lock );
free( p_filter->p_sys );
}
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
picture_t *p_outpic;
+ filter_sys_t *p_sys = p_filter->p_sys;
uint8_t *p_in_y, *p_in_u, *p_in_v, *p_in_end_u;
uint8_t *p_out_y, *p_out_u, *p_out_v;
- int i_simthres = var_GetInteger( p_filter, "colorthres-similaritythres" );
- int i_satthres = var_GetInteger( p_filter, "colorthres-saturationthres" );
- int i_color = var_GetInteger( p_filter, "colorthres-color" );
+
+ vlc_mutex_lock( &p_sys->lock );
+ int i_simthres = p_sys->i_simthres;
+ int i_satthres = p_sys->i_satthres;
+ int i_color = p_sys->i_color;
+ vlc_mutex_unlock( &p_sys->lock );
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;
}
p_out_v++;
}
- 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;
+ return CopyInfoAndRelease( p_outpic, p_pic );
+}
+
+static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+ (void)oldval; (void)p_data;
+ filter_t *p_filter = (filter_t*)p_this;
+ filter_sys_t *p_sys = p_filter->p_sys;
- if( p_pic->pf_release )
- p_pic->pf_release( p_pic );
+ if( !strcmp( psz_var, CFG_PREFIX "color" ) )
+ {
+ vlc_mutex_lock( &p_sys->lock );
+ p_sys->i_color = newval.i_int;
+ vlc_mutex_unlock( &p_sys->lock );
+ }
+ else if( !strcmp( psz_var, CFG_PREFIX "similaritythres" ) )
+ {
+ vlc_mutex_lock( &p_sys->lock );
+ p_sys->i_simthres = newval.i_int;
+ vlc_mutex_unlock( &p_sys->lock );
+ }
+ else /* CFG_PREFIX "saturationthres" */
+ {
+ vlc_mutex_lock( &p_sys->lock );
+ p_sys->i_satthres = newval.i_int;
+ vlc_mutex_unlock( &p_sys->lock );
+ }
- return p_outpic;
+ return VLC_SUCCESS;
}