]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/bluescreen.c
deinterlace: privatize two functions
[vlc] / modules / video_filter / bluescreen.c
index 0316013a1a9bb39c86a015a0ad9385410021d8d7..81362ce995d51ad1397c1850f7c2b50575a079c3 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * bluescreen.c : Bluescreen (weather channel like) video filter for vlc
  *****************************************************************************
- * Copyright (C) 2005-2007 the VideoLAN team
+ * Copyright (C) 2005-2007 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -31,9 +31,7 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
-
-#include "vlc_filter.h"
+#include <vlc_filter.h>
 
 #define BLUESCREEN_HELP N_( \
     "This effect, also known as \"greenscreen\" or \"chroma key\" blends " \
@@ -85,14 +83,14 @@ vlc_module_begin ()
     add_shortcut( "bluescreen" )
     set_callbacks( Create, Destroy )
 
-    add_integer_with_range( CFG_PREFIX "u", 120, 0, 255, NULL,
+    add_integer_with_range( CFG_PREFIX "u", 120, 0, 255,
                             BLUESCREENU_TEXT, BLUESCREENU_LONGTEXT, false )
-    add_integer_with_range( CFG_PREFIX "v", 90, 0, 255, NULL,
+    add_integer_with_range( CFG_PREFIX "v", 90, 0, 255,
                             BLUESCREENV_TEXT, BLUESCREENV_LONGTEXT, false )
-    add_integer_with_range( CFG_PREFIX "ut", 17, 0, 255, NULL,
+    add_integer_with_range( CFG_PREFIX "ut", 17, 0, 255,
                             BLUESCREENUTOL_TEXT, BLUESCREENUTOL_LONGTEXT,
                             false )
-    add_integer_with_range( CFG_PREFIX "vt", 17, 0, 255, NULL,
+    add_integer_with_range( CFG_PREFIX "vt", 17, 0, 255,
                             BLUESCREENVTOL_TEXT, BLUESCREENVTOL_LONGTEXT,
                             false )
 vlc_module_end ()
@@ -103,6 +101,7 @@ static const char *const ppsz_filter_options[] = {
 
 struct filter_sys_t
 {
+    vlc_mutex_t lock;
     int i_u, i_v, i_ut, i_vt;
     uint8_t *p_at;
 };
@@ -115,7 +114,7 @@ static int Create( vlc_object_t *p_this )
     if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVA )
     {
         msg_Err( p_filter,
-                 "Unsupported input chroma \"%4s\". "
+                 "Unsupported input chroma \"%4.4s\". "
                  "Bluescreen can only use \"YUVA\".",
                  (char*)&p_filter->fmt_in.video.i_chroma );
         return VLC_EGENERIC;
@@ -130,9 +129,11 @@ static int Create( vlc_object_t *p_this )
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
                        p_filter->p_cfg );
 
+    int val;
+    vlc_mutex_init( &p_sys->lock );
 #define GET_VAR( name, min, max )                                           \
-    p_sys->i_##name = __MIN( max, __MAX( min,                               \
-        var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ) ) );      \
+    val = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name );        \
+    p_sys->i_##name = VLC_CLIP( val, min, max );                                \
     var_AddCallback( p_filter, CFG_PREFIX #name, BluescreenCallback, p_sys );
 
     GET_VAR( u, 0x00, 0xff );
@@ -158,6 +159,7 @@ static void Destroy( vlc_object_t *p_this )
     var_DelCallback( p_filter, CFG_PREFIX "vt", BluescreenCallback, p_sys );
 
     free( p_sys->p_at );
+    vlc_mutex_destroy( &p_sys->lock );
     free( p_sys );
 }
 
@@ -177,19 +179,22 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     if( p_pic->format.i_chroma != VLC_CODEC_YUVA )
     {
         msg_Err( p_filter,
-                 "Unsupported input chroma \"%4s\". "
+                 "Unsupported input chroma \"%4.4s\". "
                  "Bluescreen can only use \"YUVA\".",
                  (char*)&p_pic->format.i_chroma );
         return NULL;
     }
 
-    p_sys->p_at = realloc( p_sys->p_at, i_lines * i_pitch * sizeof( uint8_t ) );
+    p_sys->p_at = xrealloc( p_sys->p_at,
+                            i_lines * i_pitch * sizeof( uint8_t ) );
     p_at = p_sys->p_at;
 
+    vlc_mutex_lock( &p_sys->lock );
     umin = p_sys->i_u - p_sys->i_ut >= 0x00 ? p_sys->i_u - p_sys->i_ut : 0x00;
     umax = p_sys->i_u + p_sys->i_ut <= 0xff ? p_sys->i_u + p_sys->i_ut : 0xff;
     vmin = p_sys->i_v - p_sys->i_vt >= 0x00 ? p_sys->i_v - p_sys->i_vt : 0x00;
     vmax = p_sys->i_v + p_sys->i_vt <= 0xff ? p_sys->i_v + p_sys->i_vt : 0xff;
+    vlc_mutex_unlock( &p_sys->lock );
 
     for( i = 0; i < i_lines*i_pitch; i++ )
     {
@@ -204,7 +209,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         }
     }
     /* Gaussian convolution to make it look cleaner */
-    vlc_memset( p_a, 0, 2 * i_pitch );
+    memset( p_a, 0, 2 * i_pitch );
     for( i = 2; i < i_lines - 2; i++ )
     {
         p_a[i*i_pitch] = 0x00;
@@ -259,23 +264,17 @@ static int BluescreenCallback( vlc_object_t *p_this, char const *psz_var,
     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
     filter_sys_t *p_sys = (filter_sys_t *) p_data;
 
+    vlc_mutex_lock( &p_sys->lock );
 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
     if( VAR_IS( "u" ) )
-    {
-        p_sys->i_u = __MAX( 0, __MIN( 255, newval.i_int ) );
-    }
+        p_sys->i_u = VLC_CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "v" ) )
-    {
-        p_sys->i_v = __MAX( 0, __MIN( 255, newval.i_int ) );
-    }
+        p_sys->i_v = VLC_CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "ut" ) )
-    {
-        p_sys->i_ut = __MAX( 0, __MIN( 255, newval.i_int ) );
-    }
+        p_sys->i_ut = VLC_CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "vt" ) )
-    {
-        p_sys->i_vt = __MAX( 0, __MIN( 255, newval.i_int ) );
-    }
+        p_sys->i_vt = VLC_CLIP( newval.i_int, 0, 255 );
+    vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_SUCCESS;
 }