]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/ball.c
access_dvb/dtv: support for libdvbpsi >= 1.0.0
[vlc] / modules / video_filter / ball.c
index ca1c0fad57a2f2f83d892130b754265d018e821b..c5584e714e8aa5c74df775e0dd2aa264dc39f3a2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * ball.c : Augmented reality ball video filter module
  *****************************************************************************
- * Copyright (C) 2000-2009 the VideoLAN team
+ * Copyright (C) 2000-2009 VLC authors and VideoLAN
  *
  * Author: Adrien Maglo <magsoft@videolan.org>
  *
  *         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.
  *****************************************************************************/
 
 
@@ -38,8 +38,6 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_sout.h>
-#include <vlc_vout.h>
 
 #include "vlc_filter.h"
 #include "filter_picture.h"
 
 enum { RED, GREEN, BLUE, WHITE };
 
-typedef struct
-{
-    uint8_t comp1;
-    uint8_t comp2;
-    uint8_t comp3;
-}COLOR;
-
-static COLOR colorList[4];
-
 #define COLORS_RGB \
-    colorList[RED].comp1 = 255; colorList[RED].comp2 = 0;        \
-                                colorList[RED].comp3 = 0;        \
-    colorList[GREEN].comp1 = 0; colorList[GREEN].comp2 = 255;    \
-                               colorList[GREEN].comp3 = 0;       \
-    colorList[BLUE].comp1 = 0; colorList[BLUE].comp2 = 0;        \
-                               colorList[BLUE].comp3 = 255;      \
-    colorList[WHITE].comp1 = 255; colorList[WHITE].comp2 = 255;  \
-                                  colorList[WHITE].comp3 = 255;
+    p_filter->p_sys->colorList[RED].comp1 = 255; p_filter->p_sys->colorList[RED].comp2 = 0;        \
+                                p_filter->p_sys->colorList[RED].comp3 = 0;        \
+    p_filter->p_sys->colorList[GREEN].comp1 = 0; p_filter->p_sys->colorList[GREEN].comp2 = 255;    \
+                               p_filter->p_sys->colorList[GREEN].comp3 = 0;       \
+    p_filter->p_sys->colorList[BLUE].comp1 = 0; p_filter->p_sys->colorList[BLUE].comp2 = 0;        \
+                               p_filter->p_sys->colorList[BLUE].comp3 = 255;      \
+    p_filter->p_sys->colorList[WHITE].comp1 = 255; p_filter->p_sys->colorList[WHITE].comp2 = 255;  \
+                                  p_filter->p_sys->colorList[WHITE].comp3 = 255;
 
 #define COLORS_YUV \
-    colorList[RED].comp1 = 82; colorList[RED].comp2 = 240;        \
-                                colorList[RED].comp3 = 90;        \
-    colorList[GREEN].comp1 = 145; colorList[GREEN].comp2 = 34;    \
-                               colorList[GREEN].comp3 = 54 ;      \
-    colorList[BLUE].comp1 = 41; colorList[BLUE].comp2 = 146;      \
-                               colorList[BLUE].comp3 = 240;       \
-    colorList[WHITE].comp1 = 255; colorList[WHITE].comp2 = 128;   \
-                                  colorList[WHITE].comp3 = 128;
+    p_filter->p_sys->colorList[RED].comp1 = 82; p_filter->p_sys->colorList[RED].comp2 = 240;        \
+                                p_filter->p_sys->colorList[RED].comp3 = 90;        \
+    p_filter->p_sys->colorList[GREEN].comp1 = 145; p_filter->p_sys->colorList[GREEN].comp2 = 34;    \
+                               p_filter->p_sys->colorList[GREEN].comp3 = 54 ;      \
+    p_filter->p_sys->colorList[BLUE].comp1 = 41; p_filter->p_sys->colorList[BLUE].comp2 = 146;      \
+                               p_filter->p_sys->colorList[BLUE].comp3 = 240;       \
+    p_filter->p_sys->colorList[WHITE].comp1 = 255; p_filter->p_sys->colorList[WHITE].comp2 = 128;   \
+                                  p_filter->p_sys->colorList[WHITE].comp3 = 128;
 
 
 /*****************************************************************************
@@ -107,7 +96,6 @@ static int getBallColor( vlc_object_t *p_this, char const *psz_newval );
  * Module descriptor
  *****************************************************************************/
 #define BALL_COLOR_TEXT N_("Ball color")
-#define BALL_COLOR_LONGTEXT N_("Ball color, one of \"red\", \"blue\" and \"green\".")
 
 #define EDGE_VISIBLE_TEXT N_("Edge visible")
 #define EDGE_VISIBLE_LONGTEXT N_("Set edge visibility.")
@@ -139,20 +127,20 @@ vlc_module_begin ()
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VFILTER )
 
-    add_string( FILTER_PREFIX "ball-color", "ball-color", NULL,
-                BALL_COLOR_TEXT, BALL_COLOR_LONGTEXT, false )
-    change_string_list( mode_list, mode_list_text, 0 )
+    add_string( FILTER_PREFIX "color", "red",
+                BALL_COLOR_TEXT, BALL_COLOR_TEXT, false )
+    change_string_list( mode_list, mode_list_text )
 
-    add_integer_with_range( FILTER_PREFIX "ball-speed", 4, 1, 15, NULL,
+    add_integer_with_range( FILTER_PREFIX "speed", 4, 1, 15,
                             BALL_SPEED_TEXT, BALL_SPEED_LONGTEXT, false )
 
-    add_integer_with_range( FILTER_PREFIX "ball-size", 10, 5, 30, NULL,
+    add_integer_with_range( FILTER_PREFIX "size", 10, 5, 30,
                             BALL_SIZE_TEXT, BALL_SIZE_LONGTEXT, false )
 
-    add_integer_with_range( FILTER_PREFIX "gradient-threshold", 40, 1, 200, NULL,
+    add_integer_with_range( FILTER_PREFIX "gradient-threshold", 40, 1, 200,
                             GRAD_THRESH_TEXT, GRAD_THRESH_LONGTEXT, false )
 
-    add_bool( FILTER_PREFIX "edge-visible", 1, NULL,
+    add_bool( FILTER_PREFIX "edge-visible", true,
               EDGE_VISIBLE_TEXT, EDGE_VISIBLE_LONGTEXT, true )
 
     add_shortcut( "ball" )
@@ -160,7 +148,7 @@ vlc_module_begin ()
 vlc_module_end ()
 
 static const char *const ppsz_filter_options[] = {
-    "ball-color", "ball-speed", "ball-size",
+    "color", "speed", "size",
     "gradient-threshold", "edge-visible", NULL
 };
 
@@ -216,6 +204,12 @@ struct filter_sys_t
     void ( *drawingPixelFunction )( filter_sys_t *, picture_t *,
                                     uint8_t, uint8_t, uint8_t,
                                     int, int, bool );
+    struct
+    {
+        uint8_t comp1;
+        uint8_t comp2;
+        uint8_t comp3;
+    } colorList[4];
 };
 
 
@@ -270,10 +264,10 @@ static int Create( vlc_object_t *p_this )
 
     if( !(psz_method =
         var_CreateGetNonEmptyStringCommand( p_filter,
-                                            FILTER_PREFIX "ball-color" ) ) )
+                                            FILTER_PREFIX "color" ) ) )
     {
         msg_Err( p_filter, "configuration variable "
-                 FILTER_PREFIX "ball-color empty" );
+                 FILTER_PREFIX "color empty" );
         p_filter->p_sys->ballColor = RED;
     }
     else
@@ -282,9 +276,9 @@ static int Create( vlc_object_t *p_this )
     free( psz_method );
 
     p_filter->p_sys->i_ballSize =
-            var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "ball-size" );
+            var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "size" );
     p_filter->p_sys->i_ballSpeed =
-            var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "ball-speed" );
+            var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "speed" );
     p_filter->p_sys->b_edgeVisible =
             var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "edge-visible" );
     p_filter->p_sys->i_gradThresh =
@@ -292,11 +286,11 @@ static int Create( vlc_object_t *p_this )
 
     vlc_mutex_init( &p_filter->p_sys->lock );
 
-    var_AddCallback( p_filter, FILTER_PREFIX "ball-color",
+    var_AddCallback( p_filter, FILTER_PREFIX "color",
                      ballCallback, p_filter->p_sys );
-    var_AddCallback( p_filter, FILTER_PREFIX "ball-size",
+    var_AddCallback( p_filter, FILTER_PREFIX "size",
                      ballCallback, p_filter->p_sys );
-    var_AddCallback( p_filter, FILTER_PREFIX "ball-speed",
+    var_AddCallback( p_filter, FILTER_PREFIX "speed",
                      ballCallback, p_filter->p_sys );
     var_AddCallback( p_filter, FILTER_PREFIX "edge-visible",
                      ballCallback, p_filter->p_sys );
@@ -325,6 +319,15 @@ static void Destroy( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
+    var_DelCallback( p_filter, FILTER_PREFIX "color",
+                     ballCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "size",
+                     ballCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "speed",
+                     ballCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "edge-visible",
+                     ballCallback, p_sys );
+
     vlc_mutex_destroy( &p_sys->lock );
 
     image_HandlerDelete( p_sys->p_image );
@@ -390,9 +393,9 @@ static void drawBall( filter_sys_t *p_sys, picture_t *p_outpic )
                 && j >= 0 && j < i_height )
             {
                 ( *p_sys->drawingPixelFunction )( p_sys, p_outpic,
-                                    colorList[ p_sys->ballColor ].comp1,
-                                    colorList[ p_sys->ballColor ].comp2,
-                                    colorList[ p_sys->ballColor ].comp3,
+                                    p_sys->colorList[ p_sys->ballColor ].comp1,
+                                    p_sys->colorList[ p_sys->ballColor ].comp2,
+                                    p_sys->colorList[ p_sys->ballColor ].comp3,
                                     i, j, b_skip );
             }
             b_skip = !b_skip;
@@ -544,6 +547,7 @@ static void FilterBall( filter_t *p_filter, picture_t *p_inpic,
 
     picture_t *p_converted;
     video_format_t fmt_comp;
+    memset( &fmt_comp, 0, sizeof(fmt_comp) );
 
     switch( p_filter->fmt_in.video.i_chroma )
     {
@@ -591,11 +595,11 @@ static void FilterBall( filter_t *p_filter, picture_t *p_inpic,
 
     if( !p_smooth || !p_grad_x || !p_grad_y ) return;
 
-    vlc_memcpy( p_outpic->p[0].p_pixels, p_inpic->p[0].p_pixels,
+    memcpy( p_outpic->p[0].p_pixels, p_inpic->p[0].p_pixels,
                 p_outpic->p[0].i_lines * p_outpic->p[0].i_pitch );
-    vlc_memcpy( p_outpic->p[1].p_pixels, p_inpic->p[1].p_pixels,
+    memcpy( p_outpic->p[1].p_pixels, p_inpic->p[1].p_pixels,
                 p_outpic->p[1].i_lines * p_outpic->p[1].i_pitch );
-    vlc_memcpy( p_outpic->p[2].p_pixels, p_inpic->p[2].p_pixels,
+    memcpy( p_outpic->p[2].p_pixels, p_inpic->p[2].p_pixels,
                 p_outpic->p[2].i_lines * p_outpic->p[2].i_pitch );
 
     GaussianConvolution( p_converted, p_smooth );
@@ -639,9 +643,9 @@ static void FilterBall( filter_t *p_filter, picture_t *p_inpic,
                     > p_sys->i_gradThresh )
                 {
                     ( *p_sys->drawingPixelFunction )( p_sys, p_outpic,
-                                                      colorList[ WHITE ].comp1,
-                                                      colorList[ WHITE ].comp2,
-                                                      colorList[ WHITE ].comp3,
+                                                      p_filter->p_sys->colorList[ WHITE ].comp1,
+                                                      p_filter->p_sys->colorList[ WHITE ].comp2,
+                                                      p_filter->p_sys->colorList[ WHITE ].comp3,
                                                       x, y, 0 );
                 }
             }
@@ -811,15 +815,15 @@ static int ballCallback( vlc_object_t *p_this, char const *psz_var,
     msg_Err( p_this, "Test" );
 
     vlc_mutex_lock( &p_sys->lock );
-    if( !strcmp( psz_var, FILTER_PREFIX "ball-color" ) )
+    if( !strcmp( psz_var, FILTER_PREFIX "color" ) )
     {
         p_sys->ballColor = getBallColor( p_this, newval.psz_string );
     }
-    else if( !strcmp( psz_var, FILTER_PREFIX "ball-size" ) )
+    else if( !strcmp( psz_var, FILTER_PREFIX "size" ) )
     {
         p_sys->i_ballSize = newval.i_int;
     }
-    else if( !strcmp( psz_var, FILTER_PREFIX "ball-speed" ) )
+    else if( !strcmp( psz_var, FILTER_PREFIX "speed" ) )
     {
         p_sys->i_ballSpeed = newval.i_int;
     }
@@ -838,7 +842,7 @@ static int ballCallback( vlc_object_t *p_this, char const *psz_var,
 
 
 /*****************************************************************************
- * ballCallback
+ * getBallColor
  *****************************************************************************
  * Get and assign the ball color value
  *****************************************************************************/