Commit 803d2ceb authored by Antoine Cellerier's avatar Antoine Cellerier

* mosaic.c: Bluescreen/Greenscreen/Chromakey video background replacement

method. It's still quite simple ... loads of room for improvement.
Example available here: http://people.videolan.org/~dionoea/bluescreen.mpg

* mosaic.h: remove trailing space
parent a084d72e
...@@ -75,6 +75,9 @@ struct filter_sys_t ...@@ -75,6 +75,9 @@ struct filter_sys_t
int i_vborder, i_hborder; /* border width/height between miniatures */ int i_vborder, i_hborder; /* border width/height between miniatures */
int i_alpha; /* subfilter alpha blending */ 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 */ char **ppsz_order; /* list of picture-id */
int i_order_length; int i_order_length;
...@@ -111,6 +114,12 @@ struct filter_sys_t ...@@ -111,6 +114,12 @@ struct filter_sys_t
"will be delayed accordingly (in milliseconds). For high " \ "will be delayed accordingly (in milliseconds). For high " \
"values you will need to raise file-caching and others.") "values you will need to raise file-caching and others.")
#define BLUESCREEN_TEXT N_("Enable bluescreen (aka greenscreen or chroma key) video background replacing")
#define BLUESCREENU_TEXT N_("Bluescreen chroma key U (0-255)")
#define BLUESCREENV_TEXT N_("Bluescreen chroma key V (0-255)")
#define BLUESCREENUTOL_TEXT N_("Bluescreen chroma key U tolerance")
#define BLUESCREENVTOL_TEXT N_("Bluescreen chroma key V tolerance")
static int pi_pos_values[] = { 0, 1 }; static int pi_pos_values[] = { 0, 1 };
static char * ppsz_pos_descriptions[] = static char * ppsz_pos_descriptions[] =
{ N_("auto"), N_("fixed") }; { N_("auto"), N_("fixed") };
...@@ -150,6 +159,17 @@ vlc_module_begin(); ...@@ -150,6 +159,17 @@ vlc_module_begin();
add_integer( "mosaic-delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT, add_integer( "mosaic-delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
VLC_FALSE ); VLC_FALSE );
add_bool( "mosaic-bs", 0, NULL, BLUESCREEN_TEXT,
BLUESCREEN_TEXT, VLC_FALSE );
add_integer( "mosaic-bsu", 120, NULL, BLUESCREENU_TEXT,
BLUESCREENU_TEXT, VLC_FALSE );
add_integer( "mosaic-bsv", 90, NULL, BLUESCREENV_TEXT,
BLUESCREENV_TEXT, VLC_FALSE );
add_integer( "mosaic-bsut", 17, NULL, BLUESCREENUTOL_TEXT,
BLUESCREENUTOL_TEXT, VLC_FALSE );
add_integer( "mosaic-bsvt", 17, NULL, BLUESCREENVTOL_TEXT,
BLUESCREENVTOL_TEXT, VLC_FALSE );
var_Create( p_module->p_libvlc, "mosaic-lock", VLC_VAR_MUTEX ); var_Create( p_module->p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
vlc_module_end(); vlc_module_end();
...@@ -238,7 +258,7 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -238,7 +258,7 @@ static int CreateFilter( vlc_object_t *p_this )
char *psz_end = NULL; char *psz_end = NULL;
i_index = 0; i_index = 0;
do do
{ {
psz_end = strchr( psz_order, ',' ); psz_end = strchr( psz_order, ',' );
i_index++; i_index++;
p_sys->ppsz_order = realloc( p_sys->ppsz_order, p_sys->ppsz_order = realloc( p_sys->ppsz_order,
...@@ -250,6 +270,22 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -250,6 +270,22 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->i_order_length = i_index; p_sys->i_order_length = i_index;
} }
/* 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_CreateGetBool( p_filter, "mosaic-bs" );
var_Destroy( p_filter, "mosaic-bs" );
var_Create( p_libvlc, "mosaic-bs", VLC_VAR_INTEGER );
var_SetBool( p_libvlc, "mosaic-bs", p_sys->b_bs );
var_AddCallback( p_libvlc, "mosaic-bs", MosaicCallback, p_sys );
if( p_sys->b_bs && p_sys->b_keep )
{
msg_Warn( p_filter, "mosaic-keep-picture needs to be disabled for"
" bluescreen to work" );
}
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -294,6 +330,12 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -294,6 +330,12 @@ static void DestroyFilter( vlc_object_t *p_this )
var_Destroy( p_libvlc, "mosaic-cols" ); var_Destroy( p_libvlc, "mosaic-cols" );
var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" ); var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" );
var_Destroy( p_libvlc, "mosaic-bsu" );
var_Destroy( p_libvlc, "mosaic-bsv" );
var_Destroy( p_libvlc, "mosaic-bsut" );
var_Destroy( p_libvlc, "mosaic-bsvt" );
var_Destroy( p_libvlc, "mosaic-bs" );
if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic ); if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
vlc_mutex_destroy( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock );
...@@ -488,6 +530,37 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -488,6 +530,37 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
"image resizing and chroma conversion failed" ); "image resizing and chroma conversion failed" );
continue; continue;
} }
/* Bluescreen stuff */
if( p_sys->b_bs )
{
int i;
uint8_t *p_a = p_converted->p[ A_PLANE ].p_pixels;
uint8_t *p_u = p_converted->p[ U_PLANE ].p_pixels;
uint8_t *p_v = p_converted->p[ V_PLANE ].p_pixels;
int i_lines = p_converted->p[ A_PLANE ].i_lines;
int i_pitch = p_converted->p[ A_PLANE ].i_pitch;
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_a[i] = 0x00;
}
}
}
} }
else else
{ {
......
...@@ -51,7 +51,7 @@ static bridge_t *__GetBridge( vlc_object_t *p_object ) ...@@ -51,7 +51,7 @@ static bridge_t *__GetBridge( vlc_object_t *p_object )
else else
{ {
p_bridge = val.p_address; p_bridge = val.p_address;
} }
return p_bridge; return p_bridge;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment