X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fmosaic.c;h=19d6111acd2f7abc8aaa094444a7b825483c1e45;hb=517a49ffa083d3ea076836bec3c58d4744f096a1;hp=20e5da9c7b348fa16d6cfab844d6c87875d8437c;hpb=eb57119f90b0fc1042d5b9ac6e0032fd4733d65b;p=vlc diff --git a/modules/video_filter/mosaic.c b/modules/video_filter/mosaic.c index 20e5da9c7b..19d6111acd 100644 --- a/modules/video_filter/mosaic.c +++ b/modules/video_filter/mosaic.c @@ -1,7 +1,7 @@ /***************************************************************************** * mosaic.c : Mosaic video plugin for vlc ***************************************************************************** - * Copyright (C) 2004-2005 VideoLAN + * Copyright (C) 2004-2005 the VideoLAN team * $Id$ * * Authors: Antoine Cellerier @@ -19,7 +19,7 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -75,6 +75,9 @@ struct filter_sys_t int i_vborder, i_hborder; /* 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_order_length; @@ -96,8 +99,8 @@ struct filter_sys_t #define ALIGN_TEXT N_("Mosaic alignment") #define POS_TEXT N_("Positioning method") -#define POS_LONGTEXT N_("Positioning method. auto : automatically choose " \ - "the best number of rows and columns. fixed : use the user-defined " \ +#define POS_LONGTEXT N_("Positioning method. auto: automatically choose " \ + "the best number of rows and columns. fixed: use the user-defined " \ "number of rows and columns.") #define ROWS_TEXT N_("Number of rows") #define COLS_TEXT N_("Number of columns") @@ -111,6 +114,12 @@ struct filter_sys_t "will be delayed accordingly (in milliseconds). For high " \ "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 char * ppsz_pos_descriptions[] = { N_("auto"), N_("fixed") }; @@ -124,6 +133,8 @@ static char *ppsz_align_descriptions[] = vlc_module_begin(); set_description( N_("Mosaic video sub filter") ); set_shortname( N_("Mosaic") ); + set_category( CAT_VIDEO ); + set_subcategory( SUBCAT_VIDEO_SUBPIC); set_capability( "sub filter", 0 ); set_callbacks( CreateFilter, DestroyFilter ); @@ -148,6 +159,17 @@ vlc_module_begin(); add_integer( "mosaic-delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT, 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 ); vlc_module_end(); @@ -236,7 +258,7 @@ static int CreateFilter( vlc_object_t *p_this ) char *psz_end = NULL; i_index = 0; do - { + { psz_end = strchr( psz_order, ',' ); i_index++; p_sys->ppsz_order = realloc( p_sys->ppsz_order, @@ -248,6 +270,22 @@ static int CreateFilter( vlc_object_t *p_this ) 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 ); return VLC_SUCCESS; @@ -292,6 +330,12 @@ static void DestroyFilter( vlc_object_t *p_this ) var_Destroy( p_libvlc, "mosaic-cols" ); 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 ); vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock ); @@ -486,6 +530,86 @@ 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 */ + 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 {