]> git.sesse.net Git - vlc/commitdiff
* mosaic_bridge.c: - Add "vfilters" option to apply video filters on the
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 15 Apr 2007 21:00:09 +0000 (21:00 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 15 Apr 2007 21:00:09 +0000 (21:00 +0000)
                      image before sending it to the mosaic.
                    - Add option ("chroma") to force the image chroma
                    - Remove alpha mask code
 * mosaic.c: - Remove bluescreen code
             - Misc cosmetics changes
 * bluescreen.c: New bluescreen filter (mostly cut & paste from mosaic.c)
 * alphamask.c: New alpha mask filter (mostly cut & paste from mosaic_bridge.c)
 * invert.c: don't invert the alpha plane for YUVA images (We also need to
             prevent that for RGBA images ... but that's not really used
             currently)
 * configure.ac, video_filter/Modules.am: add alphamask and bluescreen

configure.ac
modules/stream_out/mosaic_bridge.c
modules/video_filter/Modules.am
modules/video_filter/alphamask.c [new file with mode: 0644]
modules/video_filter/bluescreen.c [new file with mode: 0644]
modules/video_filter/invert.c
modules/video_filter/mosaic.c

index 723762daadf004df5bae42688fed5d62df7df5a5..b2d58eab9f621288426a77406d10746e2b2dffe6 100644 (file)
@@ -1187,7 +1187,7 @@ VLC_ADD_PLUGINS([packetizer_vc1])
 if test "${SYS}" != "mingwce"; then
   VLC_ADD_PLUGINS([access_fake access_filter_timeshift access_filter_record access_filter_dump])
   VLC_ADD_PLUGINS([gestures rc telnet hotkeys netsync showintf marq podcast shout sap fake folder])
-  VLC_ADD_PLUGINS([rss mosaic wall motiondetect clone crop erase])
+  VLC_ADD_PLUGINS([rss mosaic wall motiondetect clone crop erase bluescreen alphamask])
   VLC_ADD_PLUGINS([i420_yuy2 i422_yuy2 i420_ymga])
   VLC_ADD_PLUGINS([aout_file linear_resampler bandlimited_resampler])
   VLC_ADD_PLUGINS([float32_mixer spdif_mixer simple_channel_mixer])
index 1d98b823faae47140a1c064f75224ea267ef7a4c..ee491c252d559035bb4f0be712530eabf85cddd1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mosaic_bridge.c:
  *****************************************************************************
- * Copyright (C) 2004-2005 the VideoLAN team
+ * Copyright (C) 2004-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea@videolan.org>
@@ -34,7 +34,8 @@
 #include <vlc_block.h>
 #include <vlc_codec.h>
 
-#include "vlc_image.h"
+#include <vlc_image.h>
+#include <vlc_filter.h>
 
 #include "../video_filter/mosaic.h"
 
@@ -53,8 +54,10 @@ struct sout_stream_sys_t
     char *psz_id;
     vlc_bool_t b_inited;
 
-    picture_t *p_mask;
-    vlc_mutex_t mask_lock;
+    int i_chroma; /* force image format chroma */
+
+    filter_t **pp_vfilters;
+    int i_vfilters;
 };
 
 #define PICTURE_RING_SIZE 4
@@ -87,22 +90,6 @@ static void ReleasePicture( picture_t *p_pic )
     }
 }
 
-/* copied from video_filters/erase.c . Gruik ? */
-static void LoadMask( sout_stream_t *p_stream, const char *psz_filename )
-{
-    image_handler_t *p_image;
-    video_format_t fmt_in, fmt_out;
-    memset( &fmt_in, 0, sizeof( video_format_t ) );
-    memset( &fmt_out, 0, sizeof( video_format_t ) );
-    fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
-    if( p_stream->p_sys->p_mask )
-        p_stream->p_sys->p_mask->pf_release( p_stream->p_sys->p_mask );
-    p_image = image_HandlerCreate( p_stream );
-    p_stream->p_sys->p_mask =
-        image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
-    image_HandlerDelete( p_image );
-}
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -112,8 +99,15 @@ static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
 static int               Del ( sout_stream_t *, sout_stream_id_t * );
 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t * );
 
-static void video_del_buffer( decoder_t *, picture_t * );
-static picture_t *video_new_buffer( decoder_t * );
+inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
+inline static void video_del_buffer_filter( filter_t *, picture_t * );
+static void video_del_buffer( vlc_object_t *, picture_t * );
+
+inline static picture_t *video_new_buffer_decoder( decoder_t * );
+inline static picture_t *video_new_buffer_filter( filter_t * );
+static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
+                                    es_format_t *, void (*)( picture_t * ) );
+
 static void video_link_picture_decoder( decoder_t *, picture_t * );
 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
 static int MosaicBridgeCallback( vlc_object_t *, char const *,
@@ -135,11 +129,17 @@ static int MosaicBridgeCallback( vlc_object_t *, char const *,
 #define RATIO_TEXT N_("Sample aspect ratio")
 #define RATIO_LONGTEXT N_( \
     "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
-#define MASK_TEXT N_("Transparency mask")
-#define MASK_LONGTEXT N_( \
-    "Alpha blending transparency mask. Use's a png alpha channel.")
 
-#define SOUT_CFG_PREFIX "sout-mosaic-bridge-"
+#define VFILTER_TEXT N_("Video filter")
+#define VFILTER_LONGTEXT N_( \
+    "Video filters will be applied to the video stream." );
+
+#define CHROMA_TEXT N_("Image chroma")
+#define CHROMA_LONGTEXT N_( \
+    "Force the use of a specific chroma. Use YUVA if you're planning " \
+    "to use the Alphamask or Bluescreen video filter." );
+
+#define CFG_PREFIX "sout-mosaic-bridge-"
 
 vlc_module_begin();
     set_shortname( _( "Mosaic bridge" ) );
@@ -147,16 +147,19 @@ vlc_module_begin();
     set_capability( "sout stream", 0 );
     add_shortcut( "mosaic-bridge" );
 
-    add_string( SOUT_CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
+    add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
                 VLC_FALSE );
-    add_integer( SOUT_CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
+    add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
                  WIDTH_LONGTEXT, VLC_TRUE );
-    add_integer( SOUT_CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
+    add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
                  HEIGHT_LONGTEXT, VLC_TRUE );
-    add_string( SOUT_CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
+    add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
                 RATIO_LONGTEXT, VLC_FALSE );
-    add_string( SOUT_CFG_PREFIX "mask", NULL, NULL, MASK_TEXT,
-                MASK_LONGTEXT, VLC_FALSE );
+    add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
+                VLC_FALSE );
+
+    add_module_list( CFG_PREFIX "vfilter", "video filter2",
+                     NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
 
     set_callbacks( Open, Close );
 
@@ -164,7 +167,7 @@ vlc_module_begin();
 vlc_module_end();
 
 static const char *ppsz_sout_options[] = {
-    "id", "width", "height", "sar", "mask", NULL
+    "id", "width", "height", "sar", "vfilter", "chroma", NULL
 };
 
 /*****************************************************************************
@@ -177,7 +180,7 @@ static int Open( vlc_object_t *p_this )
     libvlc_global_data_t *p_libvlc_global = p_this->p_libvlc_global;
     vlc_value_t           val;
 
-    config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
+    config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
                        p_stream->p_cfg );
 
     p_sys = malloc( sizeof( sout_stream_sys_t ) );
@@ -192,37 +195,20 @@ static int Open( vlc_object_t *p_this )
     var_Get( p_libvlc_global, "mosaic-lock", &val );
     p_sys->p_lock = val.p_address;
 
-    var_Get( p_stream, SOUT_CFG_PREFIX "id", &val );
+    var_Get( p_stream, CFG_PREFIX "id", &val );
     p_sys->psz_id = val.psz_string;
 
     p_sys->i_height =
-        var_CreateGetIntegerCommand( p_stream, SOUT_CFG_PREFIX "height" );
-    var_AddCallback( p_stream, SOUT_CFG_PREFIX "height", MosaicBridgeCallback,
+        var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
+    var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
                      p_stream );
 
     p_sys->i_width =
-        var_CreateGetIntegerCommand( p_stream, SOUT_CFG_PREFIX "width" );
-    var_AddCallback( p_stream, SOUT_CFG_PREFIX "width", MosaicBridgeCallback,
+        var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
+    var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
                      p_stream );
 
-    vlc_mutex_init( p_stream, &p_sys->mask_lock );
-    val.psz_string =
-        var_CreateGetStringCommand( p_stream, SOUT_CFG_PREFIX "mask" );
-    var_AddCallback( p_stream, SOUT_CFG_PREFIX "mask", MosaicBridgeCallback,
-                     p_stream );
-    if( val.psz_string && *val.psz_string )
-    {
-        p_sys->p_mask = NULL;
-        LoadMask( p_stream, val.psz_string );
-        if( !p_sys->p_mask )
-            msg_Err( p_stream, "Error while loading mask (%s).",
-                     val.psz_string );
-    }
-    else
-        p_sys->p_mask = NULL;
-    free( val.psz_string );
-
-    var_Get( p_stream, SOUT_CFG_PREFIX "sar", &val );
+    var_Get( p_stream, CFG_PREFIX "sar", &val );
     if ( val.psz_string )
     {
         char *psz_parser = strchr( val.psz_string, ':' );
@@ -248,6 +234,14 @@ static int Open( vlc_object_t *p_this )
         p_sys->i_sar_num = p_sys->i_sar_den = 1;
     }
 
+    p_sys->i_chroma = 0;
+    val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
+    if( val.psz_string && strlen( val.psz_string ) >= 4 )
+    {
+        memcpy( &p_sys->i_chroma, val.psz_string, 4 );
+        msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
+    }
+
     p_stream->pf_add    = Add;
     p_stream->pf_del    = Del;
     p_stream->pf_send   = Send;
@@ -270,10 +264,6 @@ static void Close( vlc_object_t * p_this )
     if ( p_sys->psz_id )
         free( p_sys->psz_id );
 
-    vlc_mutex_destroy( &p_sys->mask_lock );
-    if( p_stream->p_sys->p_mask )
-        p_stream->p_sys->p_mask->pf_release( p_stream->p_sys->p_mask );
-
     free( p_sys );
 }
 
@@ -282,6 +272,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     bridge_t *p_bridge;
     bridged_es_t *p_es;
+    char *psz_chain, *psz_parser;
     int i;
 
     if ( p_sys->b_inited )
@@ -299,8 +290,8 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     p_sys->p_decoder->fmt_out.i_extra = 0;
     p_sys->p_decoder->fmt_out.p_extra = 0;
     p_sys->p_decoder->pf_decode_video = 0;
-    p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer;
-    p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer;
+    p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
+    p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
     p_sys->p_decoder->pf_picture_link    = video_link_picture_decoder;
     p_sys->p_decoder->pf_picture_unlink  = video_unlink_picture_decoder;
     p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
@@ -375,6 +366,64 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
 
+    /* Create user specified video filters */
+    psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
+    printf("psz_chain: \e[33;1m%s\e[0m\n", psz_chain );
+    {
+        config_chain_t *p_cfg;
+        for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
+        {
+            printf(" - %s\n", p_cfg->psz_value );
+        }
+    }
+    p_sys->i_vfilters = 0;
+    p_sys->pp_vfilters = NULL;
+    psz_parser = psz_chain;
+    while( psz_parser && *psz_parser )
+    {
+        config_chain_t *p_cfg;
+        char *psz_name;
+        filter_t **pp_vfilter;
+        psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
+        p_sys->i_vfilters++;
+        p_sys->pp_vfilters =
+            (filter_t **)realloc( p_sys->pp_vfilters,
+                                  p_sys->i_vfilters * sizeof(filter_t *) );
+        pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
+        *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
+        vlc_object_attach( *pp_vfilter, p_stream );
+        (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
+        (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
+        (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
+        if( p_sys->i_chroma )
+            (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
+        (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
+        (*pp_vfilter)->p_cfg = p_cfg;
+        (*pp_vfilter)->p_module =
+            module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
+        if( (*pp_vfilter)->p_module )
+        {
+            /* It worked! */
+            (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
+                p_sys->p_decoder->p_owner;
+            msg_Err( p_stream, "Added video filter %s to the chain",
+                     psz_name );
+        }
+        else
+        {
+            /* Crap ... we didn't find a filter */
+            msg_Warn( p_stream,
+                      "no video filter matching name \"%s\" found",
+                      psz_name );
+            vlc_object_detach( *pp_vfilter );
+            vlc_object_destroy( *pp_vfilter );
+            p_sys->i_vfilters--;
+        }
+        //if( psz_parser && *psz_parser ) psz_parser++;
+        printf("\n\npsz_parser: %s\n\n", psz_parser );
+    }
+    free( psz_chain );
+
     return (sout_stream_id_t *)p_sys;
 }
 
@@ -384,6 +433,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     bridge_t *p_bridge;
     bridged_es_t *p_es;
     vlc_bool_t b_last_es = VLC_TRUE;
+    filter_t **pp_vfilter, **pp_end;
     int i;
 
     if ( !p_sys->b_inited )
@@ -412,6 +462,18 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         }
     }
 
+    /* Destroy user specified video filters */
+    pp_vfilter = p_sys->pp_vfilters;
+    pp_end = pp_vfilter + p_sys->i_vfilters;
+    for( ; pp_vfilter < pp_end; pp_vfilter++ )
+    {
+        vlc_object_detach( *pp_vfilter );
+        if( (*pp_vfilter)->p_module )
+            module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
+        vlc_object_destroy( *pp_vfilter );
+    }
+    free( p_sys->pp_vfilters );
+
     vlc_mutex_lock( p_sys->p_lock );
 
     p_bridge = GetBridge( p_stream );
@@ -498,11 +560,9 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
             memset( &fmt_out, 0, sizeof(video_format_t) );
             fmt_in = p_sys->p_decoder->fmt_out.video;
 
-            if( p_sys->p_mask )
-            {
-                vlc_mutex_lock( &p_sys->mask_lock );
-                fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
-            }
+
+            if( p_sys->i_chroma )
+                fmt_out.i_chroma = p_sys->i_chroma;
             else
                 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
 
@@ -535,60 +595,11 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
                 msg_Err( p_stream, "image conversion failed" );
                 continue;
             }
-
-            if( p_sys->p_mask )
-            {
-                plane_t *p_mask = p_sys->p_mask->p+A_PLANE;
-                plane_t *p_apic = p_new_pic->p+A_PLANE;
-                if(    p_mask->i_visible_pitch
-                    != p_apic->i_visible_pitch
-                    || p_mask->i_visible_lines
-                    != p_apic->i_visible_lines )
-                {
-                    msg_Warn( p_stream,
-                              "Mask size (%d x %d) and image size (%d x %d) "
-                              "don't match. The mask will not be applied.",
-                              p_mask->i_visible_pitch,
-                              p_mask->i_visible_lines,
-                              p_apic->i_visible_pitch,
-                              p_apic->i_visible_lines );
-                }
-                else
-                {
-                    if( p_mask->i_pitch != p_apic->i_pitch
-                    ||  p_mask->i_lines != p_apic->i_lines )
-                    {
-                        /* visible plane sizes match ... but not the undelying
-                         * buffer. I'm not sure that this can happen,
-                         * but better safe than sorry. */
-                        int i_line;
-                        int i_lines = p_mask->i_visible_lines;
-                        uint8_t *p_src = p_mask->p_pixels;
-                        uint8_t *p_dst = p_apic->p_pixels;
-                        int i_src_pitch = p_mask->i_pitch;
-                        int i_dst_pitch = p_apic->i_pitch;
-                        int i_visible_pitch = p_mask->i_visible_pitch;
-                        for( i_line = 0; i_line < i_lines; i_line++,
-                             p_src += i_src_pitch, p_dst += i_dst_pitch )
-                        {
-                            p_stream->p_libvlc->pf_memcpy(
-                                p_dst, p_src, i_visible_pitch );
-                        }
-                    }
-                    else
-                    {
-                        /* plane sizes match */
-                        p_stream->p_libvlc->pf_memcpy(
-                            p_apic->p_pixels, p_mask->p_pixels,
-                            p_mask->i_pitch * p_mask->i_lines );
-                    }
-                }
-                vlc_mutex_unlock( &p_sys->mask_lock );
-            }
         }
         else
         {
             p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
+            /* TODO: chroma conversion if needed */
             vout_AllocatePicture( p_stream, p_new_pic, p_pic->format.i_chroma,
                                   p_pic->format.i_width, p_pic->format.i_height,
                                   p_sys->p_decoder->fmt_out.video.i_aspect );
@@ -602,8 +613,30 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
         p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
         p_new_pic->pf_release = ReleasePicture;
         p_new_pic->date = p_pic->date;
-
         p_pic->pf_release( p_pic );
+
+        if( p_sys->pp_vfilters )
+        {
+            /* Apply user specified video filters */
+            filter_t **pp_vfilter = p_sys->pp_vfilters;
+            filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
+            for( ; pp_vfilter < pp_end; pp_vfilter++ )
+            {
+                (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
+                (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
+                (*pp_vfilter)->fmt_in.video = p_new_pic->format;
+                (*pp_vfilter)->fmt_out.video = p_new_pic->format;
+                p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
+                                                             p_new_pic );
+                if( !p_new_pic )
+                {
+                    msg_Err( p_stream, "video filter failed" );
+                    break;
+                }
+            }
+            if( !p_new_pic ) continue;
+        }
+
         PushPicture( p_stream, p_new_pic );
     }
 
@@ -616,53 +649,78 @@ struct picture_sys_t
     vlc_bool_t b_dead;
 };
 
-static void video_release_buffer( picture_t *p_pic )
+static void video_release_buffer_decoder( picture_t *p_pic )
+{
+    if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
+    {
+        video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
+    }
+    else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
+}
+
+static void video_release_buffer_filter( picture_t *p_pic )
 {
     if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
     {
-        video_del_buffer( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
+        video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
     }
     else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
 }
 
-static picture_t *video_new_buffer( decoder_t *p_dec )
+inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
 {
-    decoder_owner_sys_t *p_sys = (decoder_owner_sys_t *)p_dec->p_owner;
-    picture_t **pp_ring = p_dec->p_owner->pp_pics;
+    return video_new_buffer( VLC_OBJECT( p_dec ),
+                             (decoder_owner_sys_t *)p_dec->p_owner,
+                             &p_dec->fmt_out,
+                             video_release_buffer_decoder );
+}
+
+inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
+{
+    return video_new_buffer( VLC_OBJECT( p_filter ),
+                             (decoder_owner_sys_t *)p_filter->p_owner,
+                             &p_filter->fmt_out,
+                             video_release_buffer_filter );
+}
+
+static picture_t *video_new_buffer( vlc_object_t *p_this,
+                                    decoder_owner_sys_t *p_sys,
+                                    es_format_t *fmt_out,
+                                    void ( *pf_release )( picture_t * ) )
+{
+    picture_t **pp_ring = p_sys->pp_pics;
     picture_t *p_pic;
     int i;
 
-    if( p_dec->fmt_out.video.i_width != p_sys->video.i_width ||
-        p_dec->fmt_out.video.i_height != p_sys->video.i_height ||
-        p_dec->fmt_out.video.i_chroma != p_sys->video.i_chroma ||
-        p_dec->fmt_out.video.i_aspect != p_sys->video.i_aspect )
+    if( fmt_out->video.i_width != p_sys->video.i_width ||
+        fmt_out->video.i_height != p_sys->video.i_height ||
+        fmt_out->video.i_chroma != p_sys->video.i_chroma ||
+        fmt_out->video.i_aspect != p_sys->video.i_aspect )
     {
-        if( !p_dec->fmt_out.video.i_sar_num ||
-            !p_dec->fmt_out.video.i_sar_den )
+        if( !fmt_out->video.i_sar_num ||
+            !fmt_out->video.i_sar_den )
         {
-            p_dec->fmt_out.video.i_sar_num =
-              p_dec->fmt_out.video.i_aspect * p_dec->fmt_out.video.i_height;
+            fmt_out->video.i_sar_num =
+                fmt_out->video.i_aspect * fmt_out->video.i_height;
 
-            p_dec->fmt_out.video.i_sar_den = VOUT_ASPECT_FACTOR *
-              p_dec->fmt_out.video.i_width;
+            fmt_out->video.i_sar_den =
+                VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
         }
 
-        vlc_ureduce( &p_dec->fmt_out.video.i_sar_num,
-                     &p_dec->fmt_out.video.i_sar_den,
-                     p_dec->fmt_out.video.i_sar_num,
-                     p_dec->fmt_out.video.i_sar_den, 0 );
+        vlc_ureduce( &fmt_out->video.i_sar_num,
+                     &fmt_out->video.i_sar_den,
+                     fmt_out->video.i_sar_num,
+                     fmt_out->video.i_sar_den, 0 );
 
-        if( !p_dec->fmt_out.video.i_visible_width ||
-            !p_dec->fmt_out.video.i_visible_height )
+        if( !fmt_out->video.i_visible_width ||
+            !fmt_out->video.i_visible_height )
         {
-            p_dec->fmt_out.video.i_visible_width =
-                p_dec->fmt_out.video.i_width;
-            p_dec->fmt_out.video.i_visible_height =
-                p_dec->fmt_out.video.i_height;
+            fmt_out->video.i_visible_width = fmt_out->video.i_width;
+            fmt_out->video.i_visible_height = fmt_out->video.i_height;
         }
 
-        p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
-        p_sys->video = p_dec->fmt_out.video;
+        fmt_out->video.i_chroma = fmt_out->i_codec;
+        p_sys->video = fmt_out->video;
 
         for( i = 0; i < PICTURE_RING_SIZE; i++ )
         {
@@ -700,7 +758,7 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
 
     if( i == PICTURE_RING_SIZE )
     {
-        msg_Err( p_dec, "decoder/filter is leaking pictures, "
+        msg_Err( p_this, "decoder/filter is leaking pictures, "
                  "resetting its ring buffer" );
 
         for( i = 0; i < PICTURE_RING_SIZE; i++ )
@@ -712,12 +770,12 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
     }
 
     p_pic = malloc( sizeof(picture_t) );
-    p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
-    vout_AllocatePicture( VLC_OBJECT(p_dec), p_pic,
-                          p_dec->fmt_out.video.i_chroma,
-                          p_dec->fmt_out.video.i_width,
-                          p_dec->fmt_out.video.i_height,
-                          p_dec->fmt_out.video.i_aspect );
+    fmt_out->video.i_chroma = fmt_out->i_codec;
+    vout_AllocatePicture( p_this, p_pic,
+                          fmt_out->video.i_chroma,
+                          fmt_out->video.i_width,
+                          fmt_out->video.i_height,
+                          fmt_out->video.i_aspect );
 
     if( !p_pic->i_planes )
     {
@@ -725,9 +783,9 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
         return NULL;
     }
 
-    p_pic->pf_release = video_release_buffer;
+    p_pic->pf_release = pf_release;
     p_pic->p_sys = malloc( sizeof(picture_sys_t) );
-    p_pic->p_sys->p_owner = VLC_OBJECT(p_dec);
+    p_pic->p_sys->p_owner = p_this;
     p_pic->p_sys->b_dead = VLC_FALSE;
     p_pic->i_status = RESERVED_PICTURE;
 
@@ -736,7 +794,19 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
     return p_pic;
 }
 
-static void video_del_buffer( decoder_t *p_this, picture_t *p_pic )
+inline static void video_del_buffer_decoder( decoder_t *p_this,
+                                             picture_t *p_pic )
+{
+    video_del_buffer( VLC_OBJECT( p_this ), p_pic );
+}
+
+inline static void video_del_buffer_filter( filter_t *p_this,
+                                            picture_t *p_pic )
+{
+    video_del_buffer( VLC_OBJECT( p_this ), p_pic );
+}
+
+static void video_del_buffer( vlc_object_t *p_this, picture_t *p_pic )
 {
     p_pic->i_refcount = 0;
     p_pic->i_status = DESTROYED_PICTURE;
@@ -756,7 +826,7 @@ static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
 
 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
 {
-    video_release_buffer( p_pic );
+    video_release_buffer_decoder( p_pic );
 }
 
 
@@ -771,28 +841,8 @@ static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     int i_ret = VLC_SUCCESS;
 
-#define VAR_IS( a ) !strcmp( psz_var, SOUT_CFG_PREFIX a )
-    if( VAR_IS( "mask" ) )
-    {
-        vlc_mutex_lock( &p_sys->mask_lock );
-        if( newval.psz_string && *newval.psz_string )
-        {
-            LoadMask( p_stream, newval.psz_string );
-            if( !p_sys->p_mask )
-            {
-                msg_Err( p_stream, "Error while loading mask (%s).",
-                         newval.psz_string );
-                i_ret = VLC_EGENERIC;
-            }
-        }
-        else if( p_sys->p_mask )
-        {
-            p_sys->p_mask->pf_release( p_sys->p_mask );
-            p_sys->p_mask = NULL;
-        }
-        vlc_mutex_unlock( &p_sys->mask_lock );
-    }
-    else if( VAR_IS( "height" ) )
+#define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
+    if( VAR_IS( "height" ) )
     {
         /* We create the handler before updating the value in p_sys
          * so we don't have to worry about locking */
index 250bb7b7488bb581582206324f384d9f6749eb48..b36f1fdd550f6bb627661b90c4739c8a9768b429 100644 (file)
@@ -30,4 +30,6 @@ SOURCES_colorthres = colorthres.c
 SOURCES_extract = extract.c
 SOURCES_sharpen = sharpen.c
 SOURCES_erase = erase.c
+SOURCES_bluescreen = bluescreen.c
+SOURCES_alphamask = alphamask.c
 noinst_HEADERS = filter_common.h
diff --git a/modules/video_filter/alphamask.c b/modules/video_filter/alphamask.c
new file mode 100644 (file)
index 0000000..4d64022
--- /dev/null
@@ -0,0 +1,249 @@
+/*****************************************************************************
+ * alphamask.c : Alpha layer mask video filter for vlc
+ *****************************************************************************
+ * Copyright (C) 2007 the VideoLAN team
+ * $Id: invert.c 18062 2006-11-26 14:20:34Z zorglub $
+ *
+ * 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
+ * (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.
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include <vlc_vout.h>
+
+#include <vlc_image.h>
+#include <vlc_filter.h>
+
+#define ALPHAMASK_HELP N_( \
+    "Use an image's alpha channel as a transparency mask." )
+
+#define MASK_TEXT N_("Transparency mask")
+#define MASK_LONGTEXT N_( \
+    "Alpha blending transparency mask. Use's a png alpha channel.")
+
+#define CFG_PREFIX "alphamask-"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Create      ( vlc_object_t * );
+static void Destroy     ( vlc_object_t * );
+
+static picture_t *Filter( filter_t *, picture_t * );
+static void LoadMask( filter_t *, const char * );
+static int MaskCallback( vlc_object_t *, char const *,
+                         vlc_value_t, vlc_value_t, void * );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("Alpha mask video filter") );
+    set_shortname( _("Alpha mask" ));
+    set_help( ALPHAMASK_HELP );
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_VFILTER );
+    set_capability( "video filter2", 0 );
+    add_shortcut( "alphamask" );
+    add_shortcut( "mask" );
+    set_callbacks( Create, Destroy );
+
+    add_string( CFG_PREFIX "mask", NULL, NULL, MASK_TEXT,
+                MASK_LONGTEXT, VLC_FALSE );
+vlc_module_end();
+
+static const char *ppsz_filter_options[] = {
+    "mask", NULL
+};
+
+struct filter_sys_t
+{
+    picture_t *p_mask;
+    vlc_mutex_t mask_lock;
+};
+
+static int Create( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys;
+    char *psz_string;
+
+    if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') )
+    {
+        msg_Err( p_filter,
+                 "Unsupported input chroma \"%4s\". "
+                 "Alphamask can only use \"YUVA\".",
+                 (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_sys = p_filter->p_sys;
+
+    config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
+                       p_filter->p_cfg );
+
+    vlc_mutex_init( p_filter, &p_sys->mask_lock );
+    psz_string =
+        var_CreateGetStringCommand( p_filter, CFG_PREFIX "mask" );
+    var_AddCallback( p_filter, CFG_PREFIX "mask", MaskCallback,
+                     p_filter );
+    p_sys->p_mask = NULL;
+    if( psz_string && *psz_string )
+    {
+        LoadMask( p_filter, psz_string );
+        if( !p_sys->p_mask )
+            msg_Err( p_filter, "Error while loading mask (%s).",
+                     psz_string );
+    }
+    free( psz_string );
+
+    p_filter->pf_video_filter = Filter;
+
+    return VLC_SUCCESS;
+}
+
+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;
+
+    vlc_mutex_destroy( &p_sys->mask_lock );
+    if( p_filter->p_sys->p_mask )
+        p_filter->p_sys->p_mask->pf_release( p_filter->p_sys->p_mask );
+
+    free( p_filter->p_sys );
+}
+
+static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
+{
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    vlc_mutex_lock( &p_sys->mask_lock );
+    /* TODO: this should be a seperate "video filter2" */
+    plane_t *p_mask = p_sys->p_mask->p+A_PLANE;
+    plane_t *p_apic = p_pic->p+A_PLANE;
+    if(    p_mask->i_visible_pitch
+        != p_apic->i_visible_pitch
+        || p_mask->i_visible_lines
+        != p_apic->i_visible_lines )
+    {
+        msg_Warn( p_filter,
+                  "Mask size (%d x %d) and image size (%d x %d) "
+                  "don't match. The mask will not be applied.",
+                  p_mask->i_visible_pitch,
+                  p_mask->i_visible_lines,
+                  p_apic->i_visible_pitch,
+                  p_apic->i_visible_lines );
+    }
+    else
+    {
+        if( p_mask->i_pitch != p_apic->i_pitch
+        ||  p_mask->i_lines != p_apic->i_lines )
+        {
+            /* visible plane sizes match ... but not the undelying
+             * buffer. I'm not sure that this can happen,
+             * but better safe than sorry. */
+            int i_line;
+            int i_lines = p_mask->i_visible_lines;
+            uint8_t *p_src = p_mask->p_pixels;
+            uint8_t *p_dst = p_apic->p_pixels;
+            int i_src_pitch = p_mask->i_pitch;
+            int i_dst_pitch = p_apic->i_pitch;
+            int i_visible_pitch = p_mask->i_visible_pitch;
+            for( i_line = 0; i_line < i_lines; i_line++,
+                 p_src += i_src_pitch, p_dst += i_dst_pitch )
+            {
+                p_filter->p_libvlc->pf_memcpy(
+                    p_dst, p_src, i_visible_pitch );
+            }
+        }
+        else
+        {
+            /* plane sizes match */
+            p_filter->p_libvlc->pf_memcpy(
+                p_apic->p_pixels, p_mask->p_pixels,
+                p_mask->i_pitch * p_mask->i_lines );
+        }
+    }
+    vlc_mutex_unlock( &p_sys->mask_lock );
+    return p_pic;
+}
+
+/* copied from video_filters/erase.c . Gruik ? */
+static void LoadMask( filter_t *p_filter, const char *psz_filename )
+{
+    image_handler_t *p_image;
+    video_format_t fmt_in, fmt_out;
+    memset( &fmt_in, 0, sizeof( video_format_t ) );
+    memset( &fmt_out, 0, sizeof( video_format_t ) );
+    fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
+    if( p_filter->p_sys->p_mask )
+        p_filter->p_sys->p_mask->pf_release( p_filter->p_sys->p_mask );
+    p_image = image_HandlerCreate( p_filter );
+    p_filter->p_sys->p_mask =
+        image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
+    image_HandlerDelete( p_image );
+}
+
+/*****************************************************************************
+* Callback to update params on the fly
+*****************************************************************************/
+static int MaskCallback( vlc_object_t *p_this, char const *psz_var,
+                         vlc_value_t oldval, vlc_value_t newval,
+                         void *p_data )
+{
+    filter_t *p_filter = (filter_t *)p_data;
+    filter_sys_t *p_sys = p_filter->p_sys;
+    int i_ret = VLC_SUCCESS;
+
+#define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
+    if( VAR_IS( "mask" ) )
+    {
+        vlc_mutex_lock( &p_sys->mask_lock );
+        if( newval.psz_string && *newval.psz_string )
+        {
+            LoadMask( p_filter, newval.psz_string );
+            if( !p_sys->p_mask )
+            {
+                msg_Err( p_filter, "Error while loading mask (%s).",
+                         newval.psz_string );
+                i_ret = VLC_EGENERIC;
+            }
+        }
+        else if( p_sys->p_mask )
+        {
+            p_sys->p_mask->pf_release( p_sys->p_mask );
+            p_sys->p_mask = NULL;
+        }
+        vlc_mutex_unlock( &p_sys->mask_lock );
+    }
+#undef VAR_IS
+
+    return i_ret;
+}
diff --git a/modules/video_filter/bluescreen.c b/modules/video_filter/bluescreen.c
new file mode 100644 (file)
index 0000000..f117fa5
--- /dev/null
@@ -0,0 +1,273 @@
+/*****************************************************************************
+ * bluescreen.c : Bluescreen (weather channel like) video filter for vlc
+ *****************************************************************************
+ * Copyright (C) 2005-2007 the VideoLAN team
+ * $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
+ * (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.
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include <vlc_vout.h>
+
+#include "vlc_filter.h"
+
+#define BLUESCREEN_HELP N_( \
+    "This effect, also known as \"greenscreen\" or \"chroma key\" blends " \
+    "the \"blue parts\" of the foreground image of the mosaic on the " \
+    "background (like weather forcasts). You can choose the \"key\" " \
+    "color for blending (blyyue by default)." )
+
+#define BLUESCREENU_TEXT N_("Bluescreen U value")
+#define BLUESCREENU_LONGTEXT N_( \
+        "\"U\" value for the bluescreen key color " \
+        "(in YUV values). From 0 to 255. Defaults to 120 for blue." )
+#define BLUESCREENV_TEXT N_("Bluescreen V value")
+#define BLUESCREENV_LONGTEXT N_( \
+        "\"V\" value for the bluescreen key color " \
+        "(in YUV values). From 0 to 255. Defaults to 90 for blue." )
+#define BLUESCREENUTOL_TEXT N_("Bluescreen U tolerance")
+#define BLUESCREENUTOL_LONGTEXT N_( \
+        "Tolerance of the bluescreen blender " \
+        "on color variations for the U plane. A value between 10 and 20 " \
+        "seems sensible." )
+#define BLUESCREENVTOL_TEXT N_("Bluescreen V tolerance")
+#define BLUESCREENVTOL_LONGTEXT N_( \
+        "Tolerance of the bluescreen blender " \
+        "on color variations for the V plane. A value between 10 and 20 " \
+        "seems sensible." )
+
+#define CFG_PREFIX "bluescreen-"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Create      ( vlc_object_t * );
+static void Destroy     ( vlc_object_t * );
+
+static picture_t *Filter( filter_t *, picture_t * );
+static int BluescreenCallback( vlc_object_t *, char const *,
+                               vlc_value_t, vlc_value_t, void * );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("Bluescreen video filter") );
+    set_shortname( _("Bluescreen" ));
+    set_help( BLUESCREEN_HELP );
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_VFILTER );
+    set_capability( "video filter2", 0 );
+    add_shortcut( "bluescreen" );
+    set_callbacks( Create, Destroy );
+
+    add_integer_with_range( CFG_PREFIX "u", 120, 0, 255, NULL,
+                            BLUESCREENU_TEXT, BLUESCREENU_LONGTEXT, VLC_FALSE );
+    add_integer_with_range( CFG_PREFIX "v", 90, 0, 255, NULL,
+                            BLUESCREENV_TEXT, BLUESCREENV_LONGTEXT, VLC_FALSE );
+    add_integer_with_range( CFG_PREFIX "ut", 17, 0, 255, NULL,
+                            BLUESCREENUTOL_TEXT, BLUESCREENUTOL_LONGTEXT,
+                            VLC_FALSE );
+    add_integer_with_range( CFG_PREFIX "vt", 17, 0, 255, NULL,
+                            BLUESCREENVTOL_TEXT, BLUESCREENVTOL_LONGTEXT,
+                            VLC_FALSE );
+vlc_module_end();
+
+static const char *ppsz_filter_options[] = {
+    "u", "v", "ut", "vt", NULL
+};
+
+struct filter_sys_t
+{
+    int i_u, i_v, i_ut, i_vt;
+    uint8_t *p_at;
+};
+
+static int Create( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys;
+
+    if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') )
+    {
+        msg_Err( p_filter,
+                 "Unsupported input chroma \"%4s\". "
+                 "Bluescreen can only use \"YUVA\".",
+                 (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_sys = p_filter->p_sys;
+
+    config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
+                       p_filter->p_cfg );
+
+#define GET_VAR( name, min, max )                                           \
+    p_sys->i_##name = __MIN( max, __MAX( min,                               \
+        var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ) ) );      \
+    var_AddCallback( p_filter, CFG_PREFIX #name, BluescreenCallback, p_sys );
+
+    GET_VAR( u, 0x00, 0xff );
+    GET_VAR( v, 0x00, 0xff );
+    GET_VAR( ut, 0x00, 0xff );
+    GET_VAR( vt, 0x00, 0xff );
+    p_sys->p_at = NULL;
+
+    p_filter->pf_video_filter = Filter;
+
+    return VLC_SUCCESS;
+}
+
+static void Destroy( vlc_object_t *p_this )
+{
+    filter_t *p_filter = (filter_t *)p_this;
+
+    free( p_filter->p_sys->p_at );
+    free( p_filter->p_sys );
+}
+
+static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
+{
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    int i,j;
+    int i_lines = p_pic->p[ A_PLANE ].i_lines;
+    int i_pitch = p_pic->p[ A_PLANE ].i_pitch;
+    uint8_t *p_a = p_pic->p[ A_PLANE ].p_pixels;
+    uint8_t *p_at;
+    uint8_t *p_u = p_pic->p[ U_PLANE ].p_pixels;
+    uint8_t *p_v = p_pic->p[ V_PLANE ].p_pixels;
+    uint8_t umin, umax, vmin, vmax;
+
+    if( p_pic->format.i_chroma != VLC_FOURCC('Y','U','V','A') )
+    {
+        msg_Err( p_filter,
+                 "Unsupported input chroma \"%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_at = p_sys->p_at;
+
+    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;
+
+    for( i = 0; i < i_lines*i_pitch; i++ )
+    {
+        if(    p_u[i] < umax && p_u[i] > umin
+            && p_v[i] < vmax && p_v[i] > vmin )
+        {
+            p_at[i] = 0x00;
+        }
+        else
+        {
+            p_at[i] = 0xff;
+        }
+    }
+    /* Gaussian convolution to make it look cleaner */
+    p_filter->p_libvlc->pf_memset( p_a, 0, 2 * i_pitch );
+    for( i = 2; i < i_lines - 2; i++ )
+    {
+        p_a[i*i_pitch] = 0x00;
+        p_a[i*i_pitch+1] = 0x00;
+        for( j = 2; j < i_pitch - 2; j ++ )
+        {
+            p_a[i*i_pitch+j] = (uint8_t)((
+              /* 2 rows up */
+                ( p_at[(i-2)*i_pitch+j-2]<<1 )
+              + ( p_at[(i-2)*i_pitch+j-1]<<2 )
+              + ( p_at[(i-2)*i_pitch+j]<<2 )
+              + ( p_at[(i-2)*i_pitch+j+1]<<2 )
+              + ( p_at[(i-2)*i_pitch+j+2]<<1 )
+              /* 1 row up */
+              + ( p_at[(i-1)*i_pitch+j-1]<<3 )
+              + ( p_at[(i-1)*i_pitch+j-2]<<2 )
+              + ( p_at[(i-1)*i_pitch+j]*12 )
+              + ( p_at[(i-1)*i_pitch+j+1]<<3 )
+              + ( p_at[(i-1)*i_pitch+j+2]<<2 )
+              /* */
+              + ( p_at[i*i_pitch+j-2]<<2 )
+              + ( p_at[i*i_pitch+j-1]*12 )
+              + ( p_at[i*i_pitch+j]<<4 )
+              + ( p_at[i*i_pitch+j+1]*12 )
+              + ( p_at[i*i_pitch+j+2]<<2 )
+              /* 1 row down */
+              + ( p_at[(i+1)*i_pitch+j-2]<<2 )
+              + ( p_at[(i+1)*i_pitch+j-1]<<3 )
+              + ( p_at[(i+1)*i_pitch+j]*12 )
+              + ( p_at[(i+1)*i_pitch+j+1]<<3 )
+              + ( p_at[(i+1)*i_pitch+j+2]<<2 )
+              /* 2 rows down */
+              + ( p_at[(i+2)*i_pitch+j-2]<<1 )
+              + ( p_at[(i+2)*i_pitch+j-1]<<2 )
+              + ( p_at[(i+2)*i_pitch+j]<<2 )
+              + ( p_at[(i+2)*i_pitch+j+1]<<2 )
+              + ( p_at[(i+2)*i_pitch+j+2]<<1 )
+              )/152);
+              if( p_a[i*i_pitch+j] < 0xbf ) p_a[i*i_pitch+j] = 0x00;
+        }
+    }
+    return p_pic;
+}
+
+/*****************************************************************************
+* Callback to update params on the fly
+*****************************************************************************/
+static int BluescreenCallback( vlc_object_t *p_this, char const *psz_var,
+                               vlc_value_t oldval, vlc_value_t newval,
+                               void *p_data )
+{
+    filter_sys_t *p_sys = (filter_sys_t *) p_data;
+
+#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 ) );
+    }
+    else if( VAR_IS( "v" ) )
+    {
+        p_sys->i_v = __MAX( 0, __MIN( 255, newval.i_int ) );
+    }
+    else if( VAR_IS( "ut" ) )
+    {
+        p_sys->i_ut = __MAX( 0, __MIN( 255, newval.i_int ) );
+    }
+    else if( VAR_IS( "vt" ) )
+    {
+        p_sys->i_vt = __MAX( 0, __MIN( 255, newval.i_int ) );
+    }
+
+    return VLC_SUCCESS;
+}
index 2cc54ad0291fe8718e72bb05098671850b2b7b19..54e3df008b3a7caefef6d71628824fe2db6d3825 100644 (file)
@@ -108,6 +108,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 {
     picture_t *p_outpic;
     int i_index;
+    int i_planes;
 
     if( !p_pic ) return NULL;
 
@@ -120,7 +121,20 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
 
-    for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
+    if( p_pic->format.i_chroma == VLC_FOURCC('Y','U','V','A') )
+    {
+        /* We don't want to invert the alpha plane */
+        i_planes = p_pic->i_planes - 1;
+        p_filter->p_libvlc->pf_memcpy(
+            p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
+            p_pic->p[A_PLANE].i_pitch *  p_pic->p[A_PLANE].i_lines );
+    }
+    else
+    {
+        i_planes = p_pic->i_planes;
+    }
+
+    for( i_index = 0 ; i_index < i_planes ; i_index++ )
     {
         uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
 
index 4ec6fca1bcdf3ab2ca005d0d788e7e8598123caa..5ebc83d0b1059df9930a7d6c977c8fb11f3fcf4f 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mosaic.c : Mosaic video plugin for vlc
  *****************************************************************************
- * Copyright (C) 2004-2005 the VideoLAN team
+ * Copyright (C) 2004-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea@via.ecp.fr>
  *****************************************************************************/
 static int  CreateFilter    ( vlc_object_t * );
 static void DestroyFilter   ( vlc_object_t * );
+static subpicture_t *Filter ( filter_t *, mtime_t );
 
-static subpicture_t *Filter( filter_t *, mtime_t );
-
-static int MosaicCallback( vlc_object_t *, char const *, vlc_value_t,
-                           vlc_value_t, void * );
+static int MosaicCallback   ( vlc_object_t *, char const *, vlc_value_t,
+                              vlc_value_t, void * );
 
 /*****************************************************************************
  * filter_sys_t : filter descriptor
  *****************************************************************************/
 struct filter_sys_t
 {
-    vlc_mutex_t lock;
-    vlc_mutex_t *p_lock;
+    vlc_mutex_t lock;         /* Internal filter lock */
+    vlc_mutex_t *p_lock;      /* Pointer to mosaic bridge lock */
 
     image_handler_t *p_image;
-    picture_t *p_pic;
-
-    int i_position; /* mosaic positioning method */
-    vlc_bool_t b_ar; /* do we keep the aspect ratio ? */
-    vlc_bool_t b_keep; /* do we keep the original picture format ? */
-    int i_width, i_height; /* mosaic height and width */
-    int i_cols, i_rows; /* mosaic rows and cols */
-    int i_align; /* mosaic alignment in background video */
-    int i_xoffset, i_yoffset; /* top left corner offset */
-    int i_borderw, i_borderh; /* border width/height between miniatures */
-    int i_alpha; /* subfilter alpha blending */
-
-    vlc_bool_t b_bs; /* Bluescreen vars */
-    int i_bsu, i_bsv, i_bsut, i_bsvt;
-
-    char **ppsz_order; /* list of picture-id */
+
+    int i_position;           /* Mosaic positioning method */
+    vlc_bool_t b_ar;          /* Do we keep the aspect ratio ? */
+    vlc_bool_t b_keep;        /* Do we keep the original picture format ? */
+    int i_width, i_height;    /* Mosaic height and width */
+    int i_cols, i_rows;       /* Mosaic rows and cols */
+    int i_align;              /* Mosaic alignment in background video */
+    int i_xoffset, i_yoffset; /* Top left corner offset */
+    int i_borderw, i_borderh; /* Border width/height between miniatures */
+    int i_alpha;              /* Subfilter alpha blending */
+
+    char **ppsz_order;        /* List of picture-ids */
     int i_order_length;
 
-    int *pi_x_offsets; /* list of substreams x offsets */
-    int *pi_y_offsets; /* list of substreams y offsets */
+    int *pi_x_offsets;        /* List of substreams x offsets */
+    int *pi_y_offsets;        /* List of substreams y offsets */
     int i_offsets_length;
 
     mtime_t i_delay;
@@ -165,35 +160,13 @@ struct filter_sys_t
         "according to this value (in milliseconds). For high " \
         "values you will need to raise caching at input.")
 
-#define BLUESCREEN_TEXT N_("Bluescreen" )
-#define BLUESCREEN_LONGTEXT N_( \
-        "This effect, also known as \"greenscreen\" or \"chroma key\" blends " \
-        "the \"blue parts\" of the foreground images of the mosaic on the " \
-        "background (like weather forecast). You can choose the \"key\" " \
-        "color for blending (blue by default)." )
-
-#define BLUESCREENU_TEXT N_("Bluescreen U value")
-#define BLUESCREENU_LONGTEXT N_( \
-        "\"U\" value for the bluescreen key color " \
-        "(in YUV values). From 0 to 255. Defaults to 120 for blue." )
-#define BLUESCREENV_TEXT N_("Bluescreen V value")
-#define BLUESCREENV_LONGTEXT N_( \
-        "\"V\" value for the bluescreen key color " \
-        "(in YUV values). From 0 to 255. Defaults to 90 for blue." )
-#define BLUESCREENUTOL_TEXT N_("Bluescreen U tolerance")
-#define BLUESCREENUTOL_LONGTEXT N_( \
-        "Tolerance of the bluescreen blender " \
-        "on color variations for the U plane. A value between 10 and 20 " \
-        "seems sensible." )
-#define BLUESCREENVTOL_TEXT N_("Bluescreen V tolerance")
-#define BLUESCREENVTOL_LONGTEXT N_( \
-        "Tolerance of the bluescreen blender " \
-        "on color variations for the V plane. A value between 10 and 20 " \
-        "seems sensible." )
-
+enum
+{
+    position_auto = 0, position_fixed = 1, position_offsets = 2
+};
 static int pi_pos_values[] = { 0, 1, 2 };
-static const char * ppsz_pos_descriptions[] =
-{ N_("auto"), N_("fixed"), N_("offsets") };
+static const char *ppsz_pos_descriptions[] =
+    { N_("auto"), N_("fixed"), N_("offsets") };
 
 static int pi_align_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
 static const char *ppsz_align_descriptions[] =
@@ -256,20 +229,6 @@ vlc_module_begin();
     add_integer( CFG_PREFIX "delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
                  VLC_FALSE );
 
-    set_section( N_("Bluescreen effect"), NULL );
-    add_bool( CFG_PREFIX "bs", 0, NULL, BLUESCREEN_TEXT,
-              BLUESCREEN_LONGTEXT, VLC_FALSE );
-    add_integer_with_range( CFG_PREFIX "bsu", 120, 0, 255, NULL,
-                            BLUESCREENU_TEXT, BLUESCREENU_LONGTEXT, VLC_FALSE );
-    add_integer_with_range( CFG_PREFIX "bsv", 90, 0, 255, NULL,
-                            BLUESCREENV_TEXT, BLUESCREENV_LONGTEXT, VLC_FALSE );
-    add_integer_with_range( CFG_PREFIX "bsut", 17, 0, 255, NULL,
-                            BLUESCREENUTOL_TEXT, BLUESCREENUTOL_LONGTEXT,
-                            VLC_FALSE );
-    add_integer_with_range( CFG_PREFIX "bsvt", 17, 0, 255, NULL,
-                            BLUESCREENVTOL_TEXT, BLUESCREENVTOL_LONGTEXT,
-                            VLC_FALSE );
-
     var_Create( p_module->p_libvlc_global, "mosaic-lock", VLC_VAR_MUTEX );
 vlc_module_end();
 
@@ -277,7 +236,7 @@ static const char *ppsz_filter_options[] = {
     "alpha", "height", "width", "align", "xoffset", "yoffset",
     "borderw", "borderh", "position", "rows", "cols",
     "keep-aspect-ratio", "keep-picture", "order", "offsets",
-    "delay", "bs", "bsu", "bsv", "bsut", "bsvt", NULL
+    "delay", NULL
 };
 
 /*****************************************************************************
@@ -285,9 +244,13 @@ static const char *ppsz_filter_options[] = {
  * parse the "--mosaic-offsets x1,y1,x2,y2,x3,y3" parameter
  * and set the corresponding struct filter_sys_t entries.
  *****************************************************************************/
-static void mosaic_ParseSetOffsets( vlc_object_t *p_this, filter_sys_t *p_sys, char *psz_offsets )
+#define mosaic_ParseSetOffsets( a, b, c ) \
+      __mosaic_ParseSetOffsets( VLC_OBJECT( a ), b, c )
+static void __mosaic_ParseSetOffsets( vlc_object_t *p_this,
+                                      filter_sys_t *p_sys,
+                                      char *psz_offsets )
 {
-    if( psz_offsets[0] != 0 )
+    if( *psz_offsets )
     {
         char *psz_end = NULL;
         int i_index = 0;
@@ -295,19 +258,23 @@ static void mosaic_ParseSetOffsets( vlc_object_t *p_this, filter_sys_t *p_sys, c
         {
             i_index++;
 
-            p_sys->pi_x_offsets = realloc( p_sys->pi_x_offsets, i_index * sizeof(int) );
+            p_sys->pi_x_offsets =
+                realloc( p_sys->pi_x_offsets, i_index * sizeof(int) );
             p_sys->pi_x_offsets[i_index - 1] = atoi( psz_offsets );
             psz_end = strchr( psz_offsets, ',' );
             psz_offsets = psz_end + 1;
 
-            p_sys->pi_y_offsets = realloc( p_sys->pi_y_offsets, i_index * sizeof(int) );
+            p_sys->pi_y_offsets =
+                realloc( p_sys->pi_y_offsets, i_index * sizeof(int) );
             p_sys->pi_y_offsets[i_index - 1] = atoi( psz_offsets );
             psz_end = strchr( psz_offsets, ',' );
             psz_offsets = psz_end + 1;
 
-            msg_Dbg( p_this, CFG_PREFIX "offset: id %d, x=%d, y=%d", i_index, p_sys->pi_x_offsets[i_index - 1], p_sys->pi_y_offsets[i_index - 1] );
+            msg_Dbg( p_this, CFG_PREFIX "offset: id %d, x=%d, y=%d",
+                     i_index, p_sys->pi_x_offsets[i_index - 1],
+                              p_sys->pi_y_offsets[i_index - 1]  );
 
-        } while( NULL != psz_end );
+        } while( psz_end );
         p_sys->i_offsets_length = i_index;
     }
 }
@@ -337,7 +304,6 @@ static int CreateFilter( vlc_object_t *p_this )
     }
 
     p_filter->pf_sub_filter = Filter;
-    p_sys->p_pic = NULL;
 
     vlc_mutex_init( p_filter, &p_sys->lock );
     vlc_mutex_lock( &p_sys->lock );
@@ -376,7 +342,8 @@ static int CreateFilter( vlc_object_t *p_this )
     var_AddCallback( p_filter, CFG_PREFIX "keep-aspect-ratio", MosaicCallback,
                      p_sys );
 
-    p_sys->b_keep = var_CreateGetBool( p_filter, CFG_PREFIX "keep-picture" );
+    p_sys->b_keep = var_CreateGetBoolCommand( p_filter,
+                                              CFG_PREFIX "keep-picture" );
     if ( !p_sys->b_keep )
     {
         p_sys->p_image = image_HandlerCreate( p_filter );
@@ -387,7 +354,7 @@ static int CreateFilter( vlc_object_t *p_this )
     psz_order = var_CreateGetStringCommand( p_filter, CFG_PREFIX "order" );
     var_AddCallback( p_filter, CFG_PREFIX "order", MosaicCallback, p_sys );
 
-    if( psz_order[0] != 0 )
+    if( *psz_order )
     {
         char *psz_end = NULL;
         i_index = 0;
@@ -400,7 +367,7 @@ static int CreateFilter( vlc_object_t *p_this )
             p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
                                            psz_end - psz_order );
             psz_order = psz_end+1;
-        } while( NULL !=  psz_end );
+        } while( psz_end );
         p_sys->i_order_length = i_index;
     }
 
@@ -409,22 +376,9 @@ static int CreateFilter( vlc_object_t *p_this )
     p_sys->i_offsets_length = 0;
     p_sys->pi_x_offsets = NULL;
     p_sys->pi_y_offsets = NULL;
-    mosaic_ParseSetOffsets( (vlc_object_t *) p_filter, p_sys, psz_offsets );
+    mosaic_ParseSetOffsets( p_filter, p_sys, psz_offsets );
     var_AddCallback( p_filter, CFG_PREFIX "offsets", MosaicCallback, p_sys );
 
-    /* Bluescreen specific stuff */
-    GET_VAR( bsu, 0x00, 0xff );
-    GET_VAR( bsv, 0x00, 0xff );
-    GET_VAR( bsut, 0x00, 0xff );
-    GET_VAR( bsvt, 0x00, 0xff );
-    p_sys->b_bs = var_CreateGetBoolCommand( p_filter, CFG_PREFIX "bs" );
-    var_AddCallback( p_filter, CFG_PREFIX "bs", MosaicCallback, p_sys );
-    if( p_sys->b_bs && p_sys->b_keep )
-    {
-        msg_Warn( p_filter, CFG_PREFIX "keep-picture needs to be disabled for"
-                            " bluescreen to work" );
-    }
-
     vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_SUCCESS;
@@ -461,27 +415,7 @@ static void DestroyFilter( vlc_object_t *p_this )
         free( p_sys->pi_y_offsets );
         p_sys->i_offsets_length = 0;
     }
-    var_Destroy( p_libvlc_global, CFG_PREFIX "offsets" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "alpha" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "height" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "align" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "width" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "xoffset" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "yoffset" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "vborder" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "hborder" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "position" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "rows" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "cols" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "keep-aspect-ratio" );
-
-    var_Destroy( p_libvlc_global, CFG_PREFIX "bsu" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "bsv" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "bsut" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "bsvt" );
-    var_Destroy( p_libvlc_global, CFG_PREFIX "bs" );
-
-    if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
+
     vlc_mutex_unlock( &p_sys->lock );
     vlc_mutex_destroy( &p_sys->lock );
     free( p_sys );
@@ -542,18 +476,22 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return p_spu;
     }
 
-    if ( p_sys->i_position == 2 ) /* user-defined offsets for positioning */
+    if ( p_sys->i_position == position_offsets )
     {
         /* If we have either too much or not enough offsets, fall-back
          * to automatic positioning. */
         if ( p_sys->i_offsets_length != p_sys->i_order_length )
         {
-            msg_Err( p_filter, "Number of specified offsets (%d) does not match number of input substreams in mosaic-order (%d), falling back to mosaic-position=0", p_sys->i_offsets_length, p_sys->i_order_length );
-            p_sys->i_position = 0;
+            msg_Err( p_filter,
+                     "Number of specified offsets (%d) does not match number "
+                     "of input substreams in mosaic-order (%d), falling back "
+                     "to mosaic-position=0",
+                     p_sys->i_offsets_length, p_sys->i_order_length );
+            p_sys->i_position = position_auto;
         }
     }
 
-    if ( p_sys->i_position == 0 ) /* use automatic positioning */
+    if ( p_sys->i_position == position_auto )
     {
         int i_numpics = p_sys->i_order_length; /* keep slots and all */
         for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
@@ -663,10 +601,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
             fmt_in.i_height = p_es->p_picture->format.i_height;
             fmt_in.i_width = p_es->p_picture->format.i_width;
 
-            if( p_sys->b_bs )
-                fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
-            else
-                fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
+            fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
             fmt_out.i_width = col_inner_width;
             fmt_out.i_height = row_inner_height;
 
@@ -696,86 +631,6 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
                            "image resizing and chroma conversion failed" );
                 continue;
             }
-
-            /* Bluescreen stuff */
-            if( p_sys->b_bs )
-            {
-                int i,j;
-                int i_lines = p_converted->p[ A_PLANE ].i_lines;
-                int i_pitch = p_converted->p[ A_PLANE ].i_pitch;
-                uint8_t *p_a = p_converted->p[ A_PLANE ].p_pixels;
-                uint8_t *p_at = malloc( i_lines * i_pitch * sizeof( uint8_t ) );
-                uint8_t *p_u = p_converted->p[ U_PLANE ].p_pixels;
-                uint8_t *p_v = p_converted->p[ V_PLANE ].p_pixels;
-                uint8_t umin, umax, vmin, vmax;
-                umin = p_sys->i_bsu - p_sys->i_bsut >= 0x00 ?
-                       p_sys->i_bsu - p_sys->i_bsut : 0x00;
-                umax = p_sys->i_bsu + p_sys->i_bsut <= 0xff ?
-                       p_sys->i_bsu + p_sys->i_bsut : 0xff;
-                vmin = p_sys->i_bsv - p_sys->i_bsvt >= 0x00 ?
-                       p_sys->i_bsv - p_sys->i_bsvt : 0x00;
-                vmax = p_sys->i_bsv + p_sys->i_bsvt <= 0xff ?
-                       p_sys->i_bsv + p_sys->i_bsvt : 0xff;
-
-                for( i = 0; i < i_lines*i_pitch; i++ )
-                {
-                    if(    p_u[i] < umax
-                        && p_u[i] > umin
-                        && p_v[i] < vmax
-                        && p_v[i] > vmin )
-                    {
-                        p_at[i] = 0x00;
-                    }
-                    else
-                    {
-                        p_at[i] = 0xff;
-                    }
-                }
-                /* Gaussian convolution to make it look cleaner */
-                p_filter->p_libvlc->pf_memset( p_a, 0, 2 * i_pitch );
-                for( i = 2; i < i_lines - 2; i++ )
-                {
-                    p_a[i*i_pitch] = 0x00;
-                    p_a[i*i_pitch+1] = 0x00;
-                    for( j = 2; j < i_pitch - 2; j ++ )
-                    {
-                        p_a[i*i_pitch+j] = (uint8_t)((
-                          /* 2 rows up */
-                            ( p_at[(i-2)*i_pitch+j-2]<<1 )
-                          + ( p_at[(i-2)*i_pitch+j-1]<<2 )
-                          + ( p_at[(i-2)*i_pitch+j]<<2 )
-                          + ( p_at[(i-2)*i_pitch+j+1]<<2 )
-                          + ( p_at[(i-2)*i_pitch+j+2]<<1 )
-                          /* 1 row up */
-                          + ( p_at[(i-1)*i_pitch+j-1]<<3 )
-                          + ( p_at[(i-1)*i_pitch+j-2]<<2 )
-                          + ( p_at[(i-1)*i_pitch+j]*12 )
-                          + ( p_at[(i-1)*i_pitch+j+1]<<3 )
-                          + ( p_at[(i-1)*i_pitch+j+2]<<2 )
-                          /* */
-                          + ( p_at[i*i_pitch+j-2]<<2 )
-                          + ( p_at[i*i_pitch+j-1]*12 )
-                          + ( p_at[i*i_pitch+j]<<4 )
-                          + ( p_at[i*i_pitch+j+1]*12 )
-                          + ( p_at[i*i_pitch+j+2]<<2 )
-                          /* 1 row down */
-                          + ( p_at[(i+1)*i_pitch+j-2]<<2 )
-                          + ( p_at[(i+1)*i_pitch+j-1]<<3 )
-                          + ( p_at[(i+1)*i_pitch+j]*12 )
-                          + ( p_at[(i+1)*i_pitch+j+1]<<3 )
-                          + ( p_at[(i+1)*i_pitch+j+2]<<2 )
-                          /* 2 rows down */
-                          + ( p_at[(i+2)*i_pitch+j-2]<<1 )
-                          + ( p_at[(i+2)*i_pitch+j-1]<<2 )
-                          + ( p_at[(i+2)*i_pitch+j]<<2 )
-                          + ( p_at[(i+2)*i_pitch+j+1]<<2 )
-                          + ( p_at[(i+2)*i_pitch+j+2]<<1 )
-                          )/152);
-                          if( p_a[i*i_pitch+j] < 0xbf ) p_a[i*i_pitch+j] = 0x00;
-                    }
-                }
-                free( p_at );
-            }
         }
         else
         {
@@ -799,7 +654,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
             return p_spu;
         }
 
-        /* HACK ALERT : let's fix the pointers to avoid picture duplication.
+        /* HACK ALERT: let's fix the pointers to avoid picture duplication.
          * This is necessary because p_region->picture is not a pointer
          * as it ought to be. */
         if( !p_sys->b_keep )
@@ -813,7 +668,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
             p_region->picture.pf_release = MosaicReleasePicture;
         }
 
-        if( p_sys->i_position == 2 ) /* user-defined offset */
+        if( p_sys->i_position == position_offsets )
         {
             p_region->i_x = p_sys->pi_x_offsets[i_real_index];
         }
@@ -835,7 +690,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
                     + ( col_inner_width - fmt_out.i_width ) / 2;
         }
 
-        if( p_sys->i_position == 2 ) /* user-defined offset */
+        if( p_sys->i_position == position_offsets )
         {
             p_region->i_y = p_sys->pi_y_offsets[i_real_index];
         }
@@ -958,9 +813,13 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
     }
     else if( VAR_IS( "position" ) )
     {
-        if( newval.i_int > 1 || newval.i_int < 0 )
+        if( newval.i_int > 2 || newval.i_int < 0 )
         {
-            msg_Err( p_this, "Position is either 0 (auto) or 1 (fixed)" );
+            msg_Err( p_this,
+                     "Position is either 0 (%s), 1 (%s) or 2 (%s)",
+                     ppsz_pos_descriptions[0],
+                     ppsz_pos_descriptions[1],
+                     ppsz_pos_descriptions[2] );
         }
         else
         {
@@ -995,18 +854,16 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
         vlc_mutex_lock( &p_sys->lock );
         msg_Dbg( p_this, "Changing mosaic order to %s", newval.psz_string );
 
-        p_sys->i_order_length = 0;
-        p_sys->ppsz_order = NULL;
         psz_order = newval.psz_string;
 
         while( p_sys->i_order_length-- )
         {
-#if 0
-            printf("%d\n", p_sys->ppsz_order);
-#endif
-            free( p_sys->ppsz_order );
+            free( p_sys->ppsz_order[p_sys->i_order_length] );
         }
-        if( psz_order[0] != 0 )
+        free( p_sys->ppsz_order );
+        p_sys->ppsz_order = NULL;
+
+        if( *psz_order )
         {
             char *psz_end = NULL;
             i_index = 0;
@@ -1019,7 +876,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
                 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
                                            psz_end - psz_order );
                 psz_order = psz_end+1;
-            } while( NULL !=  psz_end );
+            } while( psz_end );
             p_sys->i_order_length = i_index;
         }
 
@@ -1037,7 +894,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
         }
         p_sys->i_offsets_length = 0;
 
-        mosaic_ParseSetOffsets( (vlc_object_t *) p_this, p_sys, newval.psz_string );
+        mosaic_ParseSetOffsets( p_this, p_sys, newval.psz_string );
 
         vlc_mutex_unlock( &p_sys->lock );
     }
@@ -1056,35 +913,16 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
         }
         vlc_mutex_unlock( &p_sys->lock );
     }
-    else if( VAR_IS( "bs" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->b_bs = newval.b_bool;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
-    else if( VAR_IS( "bsu" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_bsu = __MAX( 0, __MIN( 255, newval.i_int ) );
-        vlc_mutex_unlock( &p_sys->lock );
-    }
-    else if( VAR_IS( "bsv" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_bsv = __MAX( 0, __MIN( 255, newval.i_int ) );
-        vlc_mutex_unlock( &p_sys->lock );
-    }
-    else if( VAR_IS( "bsut" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_bsut = __MAX( 0, __MIN( 255, newval.i_int ) );
-        vlc_mutex_unlock( &p_sys->lock );
-    }
-    else if( VAR_IS( "bsvt" ) )
+    else if( VAR_IS( "keep-picture" ) )
     {
         vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_bsvt = __MAX( 0, __MIN( 255, newval.i_int ) );
+        p_sys->b_keep = newval.b_bool;
+        if ( !p_sys->b_keep && !p_sys->p_image )
+        {
+            p_sys->p_image = image_HandlerCreate( p_this );
+        }
         vlc_mutex_unlock( &p_sys->lock );
     }
+
     return VLC_SUCCESS;
 }