📄 video_text.c
字号:
/***************************************************************************** * video_text.c : text manipulation functions ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN * * Authors: * * 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 "defs.h"#include <errno.h> /* errno */#include <stdlib.h> /* free() */#include <string.h> /* strerror() */#include <fcntl.h> /* open() */#include <unistd.h> /* read(), close() */#include "config.h"#include "common.h"#include "video_text.h"#include "intf_msg.h"/***************************************************************************** * vout_font_t: bitmap font ***************************************************************************** * This structure is used when the system doesn't provide a convenient function * to print simple characters in a buffer. * VOUT_FIXED_FONTs are stored in raw mode, character after character, with a * first array of characters followed by a second array of borders masks. * Therefore the border masks can't be complete if the font has pixels on the * border. *****************************************************************************/typedef struct vout_font_s{ int i_type; /* font type */ int i_width; /* character width in pixels */ int i_height; /* character height in pixels */ int i_interspacing; /* characters interspacing in pixels */ int i_bytes_per_line; /* bytes per character line */ int i_bytes_per_char; /* bytes per character */ u16 i_first; /* first character */ u16 i_last; /* last character */ byte_t * p_data; /* font character data */} vout_font_t;/* Font types */#define VOUT_FIXED_FONT 0 /* simple fixed font *//***************************************************************************** * vout_put_byte_t: PutByte function ***************************************************************************** * These functions will transform masks in a set of pixels. For each pixel, * character, then border and background masks are tested, and the first * encountered color is set. *****************************************************************************/typedef void (vout_put_byte_t)( void *p_pic, int i_byte, int i_char, int i_border, int i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color );/***************************************************************************** * Macros *****************************************************************************//* PUT_BYTE_MASK: put pixels from a byte-wide mask. It uses a branching tree * to optimize the number of tests. It is used in the PutByte functions. * This macro works for 1, 2 and 4 Bpp. */#define PUT_BYTE_MASK( i_mask, i_mask_color ) \if( i_mask & 0xf0 ) /* one from 1111 */ \{ \ if( i_mask & 0xc0 ) /* one from 1100 */ \ { \ if( i_mask & 0x80 ) /* 1000 */ \ { \ p_pic[0] = i_mask_color; \ if( i_mask & 0x40 ) /* 0100 */ \ { \ p_pic[1] = i_mask_color; \ } \ } \ else /* not 1000 means 0100 */ \ { \ p_pic[1] = i_mask_color; \ } \ if( i_mask & 0x30 ) /* one from 0011 */ \ { \ if( i_mask & 0x20 ) /* 0010 */ \ { \ p_pic[2] = i_mask_color; \ if( i_mask & 0x10 ) /* 0001 */ \ { \ p_pic[3] = i_mask_color; \ } \ } \ else /* not 0010 means 0001 */ \ { \ p_pic[3] = i_mask_color; \ } \ } \ } \ else /* not 1100 means 0011 */ \ { \ if( i_mask & 0x20 ) /* 0010 */ \ { \ p_pic[2] = i_mask_color; \ if( i_mask & 0x10 ) /* 0001 */ \ { \ p_pic[3] = i_mask_color; \ } \ } \ else /* not 0010 means 0001 */ \ { \ p_pic[3] = i_mask_color; \ } \ } \} \if( i_mask & 0x0f ) \{ \ if( i_mask & 0x0c ) /* one from 1100 */ \ { \ if( i_mask & 0x08 ) /* 1000 */ \ { \ p_pic[4] = i_mask_color; \ if( i_mask & 0x04 ) /* 0100 */ \ { \ p_pic[5] = i_mask_color; \ } \ } \ else /* not 1000 means 0100 */ \ { \ p_pic[5] = i_mask_color; \ } \ if( i_mask & 0x03 ) /* one from 0011 */ \ { \ if( i_mask & 0x02 ) /* 0010 */ \ { \ p_pic[6] = i_mask_color; \ if( i_mask & 0x01 ) /* 0001 */ \ { \ p_pic[7] = i_mask_color; \ } \ } \ else /* not 0010 means 0001 */ \ { \ p_pic[7] = i_mask_color; \ } \ } \ } \ else /* not 1100 means 0011 */ \ { \ if( i_mask & 0x02 ) /* 0010 */ \ { \ p_pic[6] = i_mask_color; \ if( i_mask & 0x01 ) /* 0001 */ \ { \ p_pic[7] = i_mask_color; \ } \ } \ else /* not 0010 means 0001 */ \ { \ p_pic[7] = i_mask_color; \ } \ } \}/***************************************************************************** * Local prototypes *****************************************************************************/static void PutByte8 ( u8 *p_pic, int i_byte, int i_char, int i_border, int i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color );static void PutByte16( u16 *p_pic, int i_byte, int i_char, int i_border, int i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color );static void PutByte24( void *p_pic, int i_byte, byte_t i_char, byte_t i_border, byte_t i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color );static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border, byte_t i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color );/***************************************************************************** * vout_LoadFont: load a bitmap font from a file ***************************************************************************** * This function will try to open a .psf font and load it. It will return * NULL on error. *****************************************************************************/vout_font_t *vout_LoadFont( const char *psz_name ){ int i_char, i_line; /* character and line indexes */ int i_file; /* source file */ byte_t pi_buffer[2]; /* file buffer */ vout_font_t * p_font; /* the font itself */ /* Open file */ i_file = open( psz_name, O_RDONLY ); if( i_file == -1 ) { intf_ErrMsg("error: can't open file '%s' (%s)\n", psz_name, strerror(errno)); return( NULL ); } /* Read magick number */ if( read( i_file, pi_buffer, 2 ) != 2 ) { intf_ErrMsg("error: unexpected end of file '%s'\n", psz_name ); close( i_file ); return( NULL ); } /* Allocate font descriptor */ p_font = malloc( sizeof( vout_font_t ) ); if( p_font == NULL ) { intf_ErrMsg("error: %s\n", strerror(ENOMEM)); close( i_file ); return( NULL ); } /* Read file */ switch( ((u16)pi_buffer[0] << 8) | pi_buffer[1] ) { case 0x3604: /* .psf file */ /* * PSF font: simple fixed font. Only the first 256 characters are read. * Those fonts are always 1 byte width, and 256 or 512 characters long. */ /* Read font header - two bytes indicate the font properties */ if( read( i_file, pi_buffer, 2 ) != 2) { intf_ErrMsg("error: unexpected end of file '%s'\n", psz_name ); free( p_font ); close( i_file ); return( NULL ); } /* Copy font properties */ p_font->i_type = VOUT_FIXED_FONT; p_font->i_width = 8; p_font->i_height = pi_buffer[1]; p_font->i_interspacing = 8; p_font->i_bytes_per_line = 1; p_font->i_bytes_per_char = pi_buffer[1];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -