]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/colorthres.c
input options whitelisting, step 2 (refs #1371)
[vlc] / modules / video_filter / colorthres.c
index 7f708858978308e3cd6e26bc4bb2ffc9519d71ef..acf4253d82859f268dbc5152976dc3837b013bea 100644 (file)
@@ -25,8 +25,6 @@
  * Preamble
  *****************************************************************************/
 #include <errno.h>
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
 #include <math.h>
 
 #include <vlc/vlc.h>
@@ -52,11 +50,12 @@ static picture_t *Filter( filter_t *, picture_t * );
     "chars are for red, then green, then blue. #000000 = black, #FF0000 = red,"\
     " #00FF00 = green, #FFFF00 = yellow (red + green), #FFFFFF = white" )
 static int pi_color_values[] = {
-  0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x0000FF00, 0x000000FF, 0x0000FFFF }; 
+  0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x0000FF00, 0x000000FF, 0x0000FFFF };
 
-static char *ppsz_color_descriptions[] = {
+static const char *ppsz_color_descriptions[] = {
   N_("Red"), N_("Fuchsia"), N_("Yellow"), N_("Lime"), N_("Blue"), N_("Aqua") };
 
+#define CFG_PREFIX "colorthres-"
 
 vlc_module_begin();
     set_description( _("Color threshold filter") );
@@ -64,16 +63,23 @@ vlc_module_begin();
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
     set_capability( "video filter2", 0 );
-    add_integer( "colorthres-color", 0x00FF0000, NULL, COLOR_TEXT,
+    add_integer( CFG_PREFIX "color", 0x00FF0000, NULL, COLOR_TEXT,
                  COLOR_LONGTEXT, VLC_FALSE );
+        change_safe();
         change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
-    add_integer( "colorthres-saturationthres", 20, NULL, "saturaton threshold",
-                 "", VLC_FALSE );
-    add_integer( "colorthres-similaritythres", 15, NULL, "similarity threshold",
-                 "", VLC_FALSE );
+    add_integer( CFG_PREFIX "saturationthres", 20, NULL,
+                 _("Saturaton threshold"), "", VLC_FALSE );
+        change_safe();
+    add_integer( CFG_PREFIX "similaritythres", 15, NULL,
+                 _("Similarity threshold"), "", VLC_FALSE );
+        change_safe();
     set_callbacks( Create, Destroy );
 vlc_module_end();
 
+static const char *ppsz_filter_options[] = {
+    "color", "saturationthes", "similaritythres", NULL
+};
+
 /*****************************************************************************
  * filter_sys_t: adjust filter method descriptor
  *****************************************************************************/
@@ -91,7 +97,13 @@ static int Create( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
 
     /* XXX: we might need to add/remove some FOURCCs ... */
-    if(   p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') )
+    if(   p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0')
+       && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','Y','U','V')
+       && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('J','4','2','0')
+       && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2')
+
+       && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','2')
+       && p_filter->fmt_in.video.i_chroma != VLC_FOURCC('J','4','2','2') )
     {
         msg_Err( p_filter, "Unsupported input chroma (%4s)",
                  (char*)&(p_filter->fmt_in.video.i_chroma) );
@@ -104,9 +116,12 @@ static int Create( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    var_Create( p_filter, "colorthres-color", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
-    var_Create( p_filter, "colorthres-similaritythres", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
-    var_Create( p_filter, "colorthres-saturationthres", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
+    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 ) );
     if( p_filter->p_sys == NULL )
@@ -214,8 +229,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         p_in_v++;
         p_out_u++;
         p_out_v++;
-            
-        
     }
 
     p_outpic->date = p_pic->date;