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

📄 win32text.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * win32text.c : Text drawing routines using the TextOut win32 API ***************************************************************************** * Copyright (C) 2002 - 2005 VideoLAN * $Id: freetype.c 10258 2005-03-10 13:37:29Z gbazin $ * * Authors: Gildas Bazin <gbazin@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., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>                                      /* malloc(), free() */#include <string.h>#include <vlc/vlc.h>#include <vlc/vout.h>#include "osd.h"#include "vlc_block.h"#include "vlc_filter.h"#include <math.h>/***************************************************************************** * Local prototypes *****************************************************************************/static int  Create ( vlc_object_t * );static void Destroy( vlc_object_t * );/* The RenderText call maps to pf_render_string, defined in vlc_filter.h */static int RenderText( filter_t *, subpicture_region_t *,                       subpicture_region_t * );static int Render( filter_t *, subpicture_region_t *, uint8_t *, int, int);static int SetFont( filter_t *, int );/***************************************************************************** * Module descriptor *****************************************************************************/#define FONT_TEXT N_("Font")#define FONT_LONGTEXT N_("Font filename")#define FONTSIZE_TEXT N_("Font size in pixels")#define FONTSIZE_LONGTEXT N_("The size of the fonts used by the osd module. " \    "If set to something different than 0 this option will override the " \    "relative font size " )#define OPACITY_TEXT N_("Opacity, 0..255")#define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of " \    "overlay text. 0 = transparent, 255 = totally opaque. " )#define COLOR_TEXT N_("Text Default Color")#define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, "\    "hexadecimal. #000000 = all colors off, 0xFF0000 = just Red, " \    "0xFFFFFF = all color on [White]" )#define FONTSIZER_TEXT N_("Font size")#define FONTSIZER_LONGTEXT N_("The size of the fonts used by the osd module" )static int   pi_sizes[] = { 20, 18, 16, 12, 6 };static char *ppsz_sizes_text[] = { N_("Smaller"), N_("Small"), N_("Normal"),                                   N_("Large"), N_("Larger") };static int pi_color_values[] = {  0x00000000, 0x00808080, 0x00C0C0C0, 0x00FFFFFF, 0x00800000,  0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x00808000, 0x00008000, 0x00008080,   0x0000FF00, 0x00800080, 0x00000080, 0x000000FF, 0x0000FFFF }; static char *ppsz_color_descriptions[] = {  N_("Black"), N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"),  N_("Red"), N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"), N_("Teal"),  N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"), N_("Aqua") };vlc_module_begin();    set_shortname( _("Text renderer"));    set_description( _("Win32 font renderer") );    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_SUBPIC );    add_integer( "win32text-fontsize", 0, NULL, FONTSIZE_TEXT,                 FONTSIZE_LONGTEXT, VLC_TRUE );    /* opacity valid on 0..255, with default 255 = fully opaque */    add_integer_with_range( "win32-opacity", 255, 0, 255, NULL,        OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );    /* hook to the color values list, with default 0x00ffffff = white */    add_integer( "win32text-color", 0x00FFFFFF, NULL, COLOR_TEXT,                 COLOR_LONGTEXT, VLC_TRUE );        change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );    add_integer( "win32text-rel-fontsize", 16, NULL, FONTSIZER_TEXT,                 FONTSIZER_LONGTEXT, VLC_FALSE );        change_integer_list( pi_sizes, ppsz_sizes_text, 0 );    set_capability( "text renderer", 50 );    add_shortcut( "text" );    set_callbacks( Create, Destroy );vlc_module_end();/***************************************************************************** * filter_sys_t: win32text local data *****************************************************************************/struct filter_sys_t{    uint8_t        i_font_opacity;    int            i_font_color;    int            i_font_size;    int            i_default_font_size;    int            i_display_height;    HDC hcdc;    HFONT hfont;    HFONT hfont_bak;    int i_logpy;};static uint8_t pi_gamma[16] =  {0x00, 0x41, 0x52, 0x63, 0x84, 0x85, 0x96, 0xa7, 0xb8, 0xc9,   0xca, 0xdb, 0xdc, 0xed, 0xee, 0xff};/***************************************************************************** * Create: creates the module *****************************************************************************/static int Create( vlc_object_t *p_this ){    filter_t *p_filter = (filter_t *)p_this;    filter_sys_t *p_sys;    char *psz_fontfile = NULL;    vlc_value_t val;    HDC hdc;    /* Allocate structure */    p_filter->p_sys = p_sys = malloc( sizeof( filter_sys_t ) );    if( !p_sys )    {        msg_Err( p_filter, "out of memory" );        return VLC_ENOMEM;    }    p_sys->i_font_size = 0;    p_sys->i_display_height = 0;    var_Create( p_filter, "win32text-font",                VLC_VAR_STRING | VLC_VAR_DOINHERIT );    var_Create( p_filter, "win32text-fontsize",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Create( p_filter, "win32text-rel-fontsize",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Create( p_filter, "win32text-opacity",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_filter, "win32text-opacity", &val );    p_sys->i_font_opacity = __MAX( __MIN( val.i_int, 255 ), 0 );    var_Create( p_filter, "win32text-color",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_filter, "win32text-color", &val );    p_sys->i_font_color = __MAX( __MIN( val.i_int, 0xFFFFFF ), 0 );    p_sys->hfont = p_sys->hfont_bak = 0;    hdc = GetDC( NULL );    p_sys->hcdc = CreateCompatibleDC( hdc );    p_sys->i_logpy = GetDeviceCaps( hdc, LOGPIXELSY );    ReleaseDC( NULL, hdc );    SetBkMode( p_sys->hcdc, TRANSPARENT );    var_Get( p_filter, "win32text-fontsize", &val );    p_sys->i_default_font_size = val.i_int;    if( SetFont( p_filter, 0 ) != VLC_SUCCESS ) goto error;    if( psz_fontfile ) free( psz_fontfile );    p_filter->pf_render_text = RenderText;    return VLC_SUCCESS; error:    if( psz_fontfile ) free( psz_fontfile );    free( p_sys );    return VLC_EGENERIC;}/***************************************************************************** * Destroy: destroy the module *****************************************************************************/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;    if( p_sys->hfont_bak ) SelectObject( p_sys->hcdc, p_sys->hfont_bak );    if( p_sys->hfont ) DeleteObject( p_sys->hfont );    DeleteDC( p_sys->hcdc );    free( p_sys );}/***************************************************************************** * Render: place string in picture ***************************************************************************** * This function merges the previously rendered win32text glyphs into a picture *****************************************************************************/static int Render( filter_t *p_filter, subpicture_region_t *p_region,                   uint8_t *p_bitmap, int i_width, int i_height ){    uint8_t *p_dst;    video_format_t fmt;    int i, i_pitch;    subpicture_region_t *p_region_tmp;    vlc_bool_t b_outline = VLC_TRUE;    /* Create a new subpicture region */    memset( &fmt, 0, sizeof(video_format_t) );    fmt.i_chroma = VLC_FOURCC('Y','U','V','P');    fmt.i_width = fmt.i_visible_width = i_width + (b_outline ? 4 : 0);

⌨️ 快捷键说明

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