* 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 $
+ * $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
*
* Preamble
*****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc_vout.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
#include <vlc_image.h>
#include <vlc_filter.h>
+#include <vlc_url.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.")
+ "Alpha blending transparency mask. Uses a png alpha channel.")
#define CFG_PREFIX "alphamask-"
/*****************************************************************************
* 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 );
- change_safe();
-vlc_module_end();
-
-static const char *ppsz_filter_options[] = {
+vlc_module_begin ()
+ set_description( N_("Alpha mask video filter") )
+ set_shortname( N_("Alpha mask" ))
+ set_help( ALPHAMASK_HELP )
+ set_category( CAT_VIDEO )
+ set_subcategory( SUBCAT_VIDEO_VFILTER )
+ set_capability( "video filter2", 0 )
+ add_shortcut( "alphamask", "mask" )
+ set_callbacks( Create, Destroy )
+
+ add_string( CFG_PREFIX "mask", NULL, MASK_TEXT,
+ MASK_LONGTEXT, false )
+vlc_module_end ()
+
+static const char *const ppsz_filter_options[] = {
"mask", NULL
};
filter_sys_t *p_sys;
char *psz_string;
- if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') )
+ if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVA )
{
msg_Err( p_filter,
- "Unsupported input chroma \"%4s\". "
+ "Unsupported input chroma \"%4.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 );
msg_Err( p_filter, "Error while loading mask (%s).",
psz_string );
}
+ else
+ p_sys->p_mask = NULL;
free( psz_string );
+ vlc_mutex_init( &p_sys->mask_lock );
+ var_AddCallback( p_filter, CFG_PREFIX "mask", MaskCallback,
+ p_filter );
p_filter->pf_video_filter = Filter;
return VLC_SUCCESS;
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
+ var_DelCallback( p_filter, CFG_PREFIX "mask", MaskCallback,
+ p_filter );
+
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 );
+ if( p_sys->p_mask )
+ picture_Release( p_sys->p_mask );
- free( p_filter->p_sys );
+ free( p_sys );
}
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
|| p_mask->i_visible_lines
!= p_apic->i_visible_lines )
{
- msg_Warn( p_filter,
+ msg_Err( 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,
}
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 underlying
- * 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 );
- }
+ plane_CopyPixels( p_apic, p_mask );
}
vlc_mutex_unlock( &p_sys->mask_lock );
return p_pic;
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');
+ fmt_out.i_chroma = VLC_CODEC_YUVA;
if( p_filter->p_sys->p_mask )
- p_filter->p_sys->p_mask->pf_release( p_filter->p_sys->p_mask );
+ picture_Release( p_filter->p_sys->p_mask );
p_image = image_HandlerCreate( p_filter );
+ char *psz_url = make_URI( psz_filename, NULL );
p_filter->p_sys->p_mask =
- image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
+ image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
+ free( psz_url );
image_HandlerDelete( p_image );
}
vlc_value_t oldval, vlc_value_t newval,
void *p_data )
{
+ VLC_UNUSED(p_this); VLC_UNUSED(oldval);
filter_t *p_filter = (filter_t *)p_data;
filter_sys_t *p_sys = p_filter->p_sys;
int i_ret = VLC_SUCCESS;
}
else if( p_sys->p_mask )
{
- p_sys->p_mask->pf_release( p_sys->p_mask );
+ picture_Release( p_sys->p_mask );
p_sys->p_mask = NULL;
}
vlc_mutex_unlock( &p_sys->mask_lock );