📄 logo.c
字号:
/***************************************************************************** * logo.c : logo video plugin for vlc ***************************************************************************** * Copyright (C) 2003-2006 the VideoLAN team * $Id: logo.c 18201 2006-12-02 14:59:52Z hartman $ * * Authors: Gildas Bazin <gbazin@videolan.org> * Simon Latapie <garf@videolan.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"#include "filter_common.h"#include "vlc_image.h"#include "vlc_osd.h"#ifdef LoadImage# undef LoadImage#endif/***************************************************************************** * Local prototypes *****************************************************************************/static int Create ( vlc_object_t * );static void Destroy ( vlc_object_t * );static int Init ( vout_thread_t * );static void End ( vout_thread_t * );static void Render ( vout_thread_t *, picture_t * );static int SendEvents( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );static int MouseEvent( vlc_object_t *, char const *, vlc_value_t , vlc_value_t , void * );static int Control ( vout_thread_t *, int, va_list );static int CreateFilter ( vlc_object_t * );static void DestroyFilter( vlc_object_t * );static int LogoCallback( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );/***************************************************************************** * Module descriptor *****************************************************************************/#define FILE_TEXT N_("Logo filenames")#define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \"<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \"If you only have one file, simply enter its filename.")#define REPEAT_TEXT N_("Logo animation # of loops")#define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \ "1 = continuous, 0 = disabled")#define DELAY_TEXT N_("Logo individual image time in ms")#define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")#define POSX_TEXT N_("X coordinate")#define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \ "by left-clicking it." )#define POSY_TEXT N_("Y coordinate")#define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \ "by left-clicking it." )#define TRANS_TEXT N_("Transparency of the logo")#define TRANS_LONGTEXT N_("Logo transparency value " \ "(from 0 for full transparency to 255 for full opacity)." )#define POS_TEXT N_("Logo position")#define POS_LONGTEXT N_( \ "Enforce the logo position on the video " \ "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \ "also use combinations of these values, eg 6 = top-right).")static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };static char *ppsz_pos_descriptions[] ={ N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"), N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };vlc_module_begin(); set_description( _("Logo video filter") ); set_capability( "video filter", 0 ); set_shortname( _("Logo overlay") ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_SUBPIC ); add_shortcut( "logo" ); set_callbacks( Create, Destroy ); add_file( "logo-file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE ); add_integer( "logo-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE ); add_integer( "logo-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE ); /* default to 1000 ms per image, continuously cycle through them */ add_integer( "logo-delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE ); add_integer( "logo-repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE ); add_integer_with_range( "logo-transparency", 255, 0, 255, NULL, TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE ); add_integer( "logo-position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE ); change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 ); /* subpicture filter submodule */ add_submodule(); set_capability( "sub filter", 0 ); set_callbacks( CreateFilter, DestroyFilter ); set_description( _("Logo sub filter") ); add_shortcut( "logo" );vlc_module_end();/***************************************************************************** * Structure to hold the set of individual logo image names, times, * transparencies ****************************************************************************/typedef struct{ char *psz_file; /* candidate for deletion -- not needed */ int i_delay; /* -1 means use default delay */ int i_alpha; /* -1 means use default alpha */ picture_t *p_pic;} logo_t;/***************************************************************************** * Logo list structure. Common to both the vout and sub picture filter ****************************************************************************/typedef struct{ logo_t *p_logo; /* the parsing's result */ unsigned int i_count; /* the number of logo images to be displayed */ int i_repeat; /* how often to repeat the images, image time in ms */ mtime_t i_next_pic; /* when to bring up a new logo image */ unsigned int i_counter; /* index into the list of logo images */ int i_delay; /* default delay (0 - 60000 ms) */ int i_alpha; /* default alpha */ char *psz_filename; /* --logo-file string ( is it really useful * to store it ? ) */ vlc_mutex_t lock;} logo_list_t;/***************************************************************************** * LoadImage: loads the logo image into memory *****************************************************************************/static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename ){ picture_t *p_pic; image_handler_t *p_image; video_format_t fmt_in = {0}, fmt_out = {0}; fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A'); p_image = image_HandlerCreate( p_this ); p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out ); image_HandlerDelete( p_image ); return p_pic;}/***************************************************************************** * LoadLogoList: loads the logo images into memory ***************************************************************************** * Read the logo-file input switch, obtaining a list of images and associated * durations and transparencies. Store the image(s), and times. An image * without a stated time or transparency will use the logo-delay and * logo-transparency values. *****************************************************************************/#define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list ){ char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */ unsigned int i; logo_t *p_logo; /* the parsing's result */ p_logo_list->i_counter = 0; p_logo_list->i_next_pic = 0; psz_list = strdup( p_logo_list->psz_filename ); /* Count the number logos == number of ';' + 1 */ p_logo_list->i_count = 1; for( i = 0; i < strlen( psz_list ); i++ ) { if( psz_list[i] == ';' ) p_logo_list->i_count++; } p_logo_list->p_logo = p_logo = (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) ); /* Fill the data */ for( i = 0; i < p_logo_list->i_count; i++ ) { char *p_c; char *p_c2; p_c = strchr( psz_list, ';' ); p_c2 = strchr( psz_list, ',' ); p_logo[i].i_alpha = -1; /* use default settings */ p_logo[i].i_delay = -1; /* use default settings */ if( p_c2 && ( p_c2 < p_c || !p_c ) ) { /* <logo>,<delay>[,<alpha>] type */ if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' ) p_logo[i].i_delay = atoi( p_c2+1 ); *p_c2 = '\0'; if( ( p_c2 = strchr( p_c2+1, ',' ) ) && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' ) p_logo[i].i_alpha = atoi( p_c2 + 1 ); } else { /* <logo> type */ if( p_c ) *p_c = '\0'; } p_logo[i].psz_file = strdup( psz_list ); p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file ); if( !p_logo[i].p_pic ) { msg_Warn( p_this, "error while loading logo %s, will be skipped", p_logo[i].psz_file ); } if( p_c ) psz_list = p_c + 1; } for( i = 0; i < p_logo_list->i_count; i++ ) { msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d", p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha ); } /* initialize so that on the first update it will wrap back to 0 */ p_logo_list->i_counter = p_logo_list->i_count;}/***************************************************************************** * FreeLogoList *****************************************************************************/#define FREE( a ) free(a);a=NULL;void FreeLogoList( logo_list_t *p_logo_list ){ unsigned int i; if( p_logo_list->psz_filename ) FREE( p_logo_list->psz_filename ); for( i = 0; i < p_logo_list->i_count; i++ ) { logo_t *p_logo = &p_logo_list->p_logo[i]; if( p_logo->psz_file ) FREE( p_logo->psz_file ); if( p_logo->p_pic ) { p_logo->p_pic->pf_release( p_logo->p_pic ); p_logo->p_pic = NULL; } }}#undef FREE/***************************************************************************** * vout_sys_t: logo video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the Invert specific properties of an output thread. *****************************************************************************/struct vout_sys_t{ logo_list_t *p_logo_list; vout_thread_t *p_vout; filter_t *p_blend; int i_width, i_height; int pos, posx, posy;};/***************************************************************************** * Create: allocates logo video thread output method *****************************************************************************/static int Create( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys; vlc_value_t val; logo_list_t *p_logo_list; /* Allocate structure */ p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_sys == NULL ) { msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; } p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) ); if( p_logo_list == NULL ) { msg_Err( p_vout, "out of memory" ); free( p_sys ); return VLC_ENOMEM;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -