⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svg.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * svg.c : Put SVG on the video ***************************************************************************** * Copyright (C) 2002, 2003 the VideoLAN team * $Id: svg.c 16647 2006-09-14 14:58:57Z hartman $ * * Authors: Olivier Aubert <oaubert@lisi.univ-lyon1.fr> * * 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_osd.h"#include "vlc_block.h"#include "vlc_filter.h"#ifdef HAVE_SYS_TYPES_H#   include <sys/types.h>#endif#ifdef HAVE_UNISTD_H#    include <unistd.h>#elif defined( WIN32 ) && !defined( UNDER_CE )#   include <io.h>#endif#include <glib.h>#include <glib/gstdio.h>#include <glib-object.h>                                  /* g_object_unref( ) */#include <librsvg-2/librsvg/rsvg.h>typedef struct svg_rendition_t svg_rendition_t;/***************************************************************************** * Local prototypes *****************************************************************************/static int  Create    ( vlc_object_t * );static void Destroy   ( vlc_object_t * );static int  RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,                        subpicture_region_t *p_region_in );/***************************************************************************** * Module descriptor *****************************************************************************/#define TEMPLATE_TEXT N_( "SVG template file" )#define TEMPLATE_LONGTEXT N_( "Location of a file holding a SVG template "\        "for automatic string conversion" )vlc_module_begin(); set_category( CAT_INPUT); set_category( SUBCAT_INPUT_SCODEC ); set_capability( "text renderer", 99 ); add_shortcut( "svg" ); add_string( "svg-template-file", "", NULL, TEMPLATE_TEXT, TEMPLATE_LONGTEXT, VLC_TRUE ); set_callbacks( Create, Destroy );vlc_module_end();/**   Describes a SVG string to be displayed on the video*/struct svg_rendition_t{    int            i_width;    int            i_height;    int            i_chroma;    /** The SVG source associated with this subpicture */    char           *psz_text;    /* The rendered SVG, as a GdkPixbuf */    GdkPixbuf      *p_rendition;};static int Render( filter_t *, subpicture_region_t *, svg_rendition_t *, int, int);static char *svg_GetTemplate ();static void svg_set_size( filter_t *p_filter, int width, int height );static void svg_SizeCallback  ( int *width, int *height, gpointer data );static void svg_RenderPicture ( filter_t *p_filter,                                svg_rendition_t *p_svg );static void FreeString( svg_rendition_t * );/***************************************************************************** * filter_sys_t: svg local data ***************************************************************************** * This structure is part of the filter thread descriptor. * It describes the svg specific properties of an output thread. *****************************************************************************/struct filter_sys_t{    /* The SVG template used to convert strings */    char          *psz_template;    /* Default size for rendering. Initialized to the output size. */    int            i_width;    int            i_height;    vlc_mutex_t   *lock;};/***************************************************************************** * Create: allocates svg video thread output method ***************************************************************************** * This function allocates and initializes a  vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){    filter_t *p_filter = ( filter_t * )p_this;    filter_sys_t *p_sys;    /* Allocate structure */    p_sys = malloc( sizeof( filter_sys_t ) );    if( !p_sys )    {        msg_Err( p_filter, "out of memory" );        return VLC_ENOMEM;    }    /* Initialize psz_template */    p_sys->psz_template = svg_GetTemplate( p_this );    if( !p_sys->psz_template )    {        msg_Err( p_filter, "out of memory" );        return VLC_ENOMEM;    }    p_sys->i_width = p_filter->fmt_out.video.i_width;    p_sys->i_height = p_filter->fmt_out.video.i_height;    p_filter->pf_render_text = RenderText;    p_filter->p_sys = p_sys;    /* MUST call this before any RSVG funcs */    rsvg_init( );    return VLC_SUCCESS;}static char *svg_GetTemplate( vlc_object_t *p_this ){    filter_t *p_filter = ( filter_t * )p_this;    char *psz_filename;    char *psz_template;    FILE *file;    psz_filename = config_GetPsz( p_filter, "svg-template-file" );    if( !psz_filename || psz_filename[0] == 0 )    {        /* No filename. Use a default value. */        psz_template = NULL;    }    else    {        /* Read the template */        file = utf8_fopen( psz_filename, "rt" );        if( !file )        {            msg_Warn( p_this, "SVG template file %s does not exist.",                                         psz_filename );            psz_template = NULL;        }        else        {            struct stat s;            int i_ret;            i_ret = utf8_stat( psz_filename, &s );            if( i_ret )            {                /* Problem accessing file information. Should not                   happen as we could open it. */                psz_template = NULL;            }            else            if( ((signed)s.st_size) < 0 )            {                msg_Err( p_this, "SVG template too big" );                psz_template = NULL;            }            else            {                msg_Dbg( p_this, "reading %ld bytes from template %s",                         (unsigned long)s.st_size, psz_filename );                psz_template = malloc( ( s.st_size + 42 ) * sizeof( char ) );                if( !psz_template )                {                    msg_Err( p_filter, "out of memory" );                    return NULL;                }                memset( psz_template, 0, s.st_size + 1 );                fread( psz_template, s.st_size, 1, file );                fclose( file );            }        }    }    if( !psz_template )    {        /* Either there was no file, or there was an error.           Use the default value */        psz_template = strdup( "<?xml version='1.0' encoding='UTF-8' standalone='no'?> \<svg version='1' preserveAspectRatio='xMinYMin meet' viewBox='0 0 800 600'> \  <text x='10' y='560' fill='white' font-size='32'  \        font-family='sans-serif'>%s</text></svg>" );    }    return psz_template;}/***************************************************************************** * Destroy: destroy Clone video thread output method ***************************************************************************** * Clean up all data and library connections *****************************************************************************/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;    free( p_sys->psz_template );    free( p_sys );    rsvg_term( );}/***************************************************************************** * Render: render SVG in picture *****************************************************************************/static int Render( filter_t *p_filter, subpicture_region_t *p_region,                   svg_rendition_t *p_svg, int i_width, int i_height ){    video_format_t fmt;    uint8_t *p_y, *p_u, *p_v, *p_a;    int x, y, i_pitch, i_u_pitch;    guchar *pixels_in = NULL;    int rowstride_in;    int channels_in;    int alpha;    picture_t *p_pic;    subpicture_region_t *p_region_tmp;    if ( p_filter->p_sys->i_width != i_width ||

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -