Commit ce0e4fb0 authored by Antoine Cellerier's avatar Antoine Cellerier

* mosaic_bridge.c: - Add "vfilters" option to apply video filters on the

                      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
parent 4cdb486b
...@@ -1187,7 +1187,7 @@ VLC_ADD_PLUGINS([packetizer_vc1]) ...@@ -1187,7 +1187,7 @@ VLC_ADD_PLUGINS([packetizer_vc1])
if test "${SYS}" != "mingwce"; then if test "${SYS}" != "mingwce"; then
VLC_ADD_PLUGINS([access_fake access_filter_timeshift access_filter_record access_filter_dump]) 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([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([i420_yuy2 i422_yuy2 i420_ymga])
VLC_ADD_PLUGINS([aout_file linear_resampler bandlimited_resampler]) VLC_ADD_PLUGINS([aout_file linear_resampler bandlimited_resampler])
VLC_ADD_PLUGINS([float32_mixer spdif_mixer simple_channel_mixer]) VLC_ADD_PLUGINS([float32_mixer spdif_mixer simple_channel_mixer])
......
This diff is collapsed.
...@@ -30,4 +30,6 @@ SOURCES_colorthres = colorthres.c ...@@ -30,4 +30,6 @@ SOURCES_colorthres = colorthres.c
SOURCES_extract = extract.c SOURCES_extract = extract.c
SOURCES_sharpen = sharpen.c SOURCES_sharpen = sharpen.c
SOURCES_erase = erase.c SOURCES_erase = erase.c
SOURCES_bluescreen = bluescreen.c
SOURCES_alphamask = alphamask.c
noinst_HEADERS = filter_common.h noinst_HEADERS = filter_common.h
/*****************************************************************************
* 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;
}
This diff is collapsed.
...@@ -108,6 +108,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -108,6 +108,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
picture_t *p_outpic; picture_t *p_outpic;
int i_index; int i_index;
int i_planes;
if( !p_pic ) return NULL; if( !p_pic ) return NULL;
...@@ -120,7 +121,20 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -120,7 +121,20 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
return NULL; 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; uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
......
This diff is collapsed.
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