📄 subsass.c
字号:
/***************************************************************************** * subsass.c : ASS/SSA subtitles decoder ***************************************************************************** * Copyright (C) 2000-2006 the VideoLAN team * $Id$ * * Authors: Gildas Bazin <gbazin@videolan.org> * Samuel Hocevar <sam@zoy.org> * Derk-Jan Hartman <hartman at videolan dot 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. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "subsdec.h"void ParseSSAString( decoder_t *p_dec, char *psz_subtitle, subpicture_t *p_spu_in ){ /* We expect MKV formatted SSA: * ReadOrder, Layer, Style, CharacterName, MarginL, MarginR, * MarginV, Effect, Text */ decoder_sys_t *p_sys = p_dec->p_sys; subpicture_t *p_spu = p_spu_in; ssa_style_t *p_style = NULL; char *psz_new_subtitle = NULL; char *psz_buffer_sub = NULL; char *psz_style = NULL; char *psz_style_start = NULL; char *psz_style_end = NULL; int i_text = 0, i_comma = 0, i_strlen = 0, i; int i_margin_l = 0, i_margin_r = 0, i_margin_v = 0; psz_buffer_sub = psz_subtitle; p_spu->p_region->psz_html = NULL; i_comma = 0; while( i_comma < 8 && *psz_buffer_sub != '\0' ) { if( *psz_buffer_sub == ',' ) { i_comma++; if( i_comma == 2 ) psz_style_start = &psz_buffer_sub[1]; else if( i_comma == 3 ) psz_style_end = &psz_buffer_sub[0]; else if( i_comma == 4 ) i_margin_l = (int)strtol( &psz_buffer_sub[1], NULL, 10 ); else if( i_comma == 5 ) i_margin_r = (int)strtol( &psz_buffer_sub[1], NULL, 10 ); else if( i_comma == 6 ) i_margin_v = (int)strtol( &psz_buffer_sub[1], NULL, 10 ); } psz_buffer_sub++; } if( *psz_buffer_sub == '\0' && i_comma == 8 ) { msg_Dbg( p_dec, "couldn't find all fields in this SSA line" ); return; } psz_new_subtitle = malloc( strlen( psz_buffer_sub ) + 1); i_text = 0; while( psz_buffer_sub[0] != '\0' ) { if( psz_buffer_sub[0] == '\\' && psz_buffer_sub[1] == 'n' ) { psz_new_subtitle[i_text] = ' '; i_text++; psz_buffer_sub += 2; } else if( psz_buffer_sub[0] == '\\' && psz_buffer_sub[1] == 'N' ) { psz_new_subtitle[i_text] = '\n'; i_text++; psz_buffer_sub += 2; } else if( psz_buffer_sub[0] == '{' && psz_buffer_sub[1] == '\\' ) { /* SSA control code */ while( psz_buffer_sub[0] != '\0' && psz_buffer_sub[0] != '}' ) { psz_buffer_sub++; } psz_buffer_sub++; } else { psz_new_subtitle[i_text] = psz_buffer_sub[0]; i_text++; psz_buffer_sub++; } } psz_new_subtitle[i_text] = '\0'; i_strlen = __MAX( psz_style_end - psz_style_start, 0); psz_style = strndup( psz_style_start, i_strlen ); for( i = 0; i < p_sys->i_ssa_styles; i++ ) { if( !strcmp( p_sys->pp_ssa_styles[i]->psz_stylename, psz_style ) ) p_style = p_sys->pp_ssa_styles[i]; } free( psz_style ); p_spu->p_region->psz_text = psz_new_subtitle; if( p_style == NULL ) { p_spu->p_region->i_align = SUBPICTURE_ALIGN_BOTTOM | p_sys->i_align; p_spu->i_x = p_sys->i_align ? 20 : 0; p_spu->i_y = 10; } else { msg_Dbg( p_dec, "style is: %s", p_style->psz_stylename); p_spu->p_region->p_style = &p_style->font_style; p_spu->p_region->i_align = p_style->i_align; if( p_style->i_align & SUBPICTURE_ALIGN_LEFT ) { p_spu->i_x = (i_margin_l) ? i_margin_l : p_style->i_margin_h; } else if( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) { p_spu->i_x = (i_margin_r) ? i_margin_r : p_style->i_margin_h; } p_spu->i_y = (i_margin_v) ? i_margin_v : p_style->i_margin_v; }}/***************************************************************************** * ParseColor: SSA stores color in BBGGRR, in ASS it uses AABBGGRR * The string value in the string can be a pure integer, or hexadecimal &HBBGGRR *****************************************************************************/static void ParseColor( char *psz_color, int *pi_color, int *pi_alpha ){ int i_color = 0; if( !strncasecmp( psz_color, "&H", 2 ) ) { /* textual HEX representation */ i_color = (int) strtol( psz_color+2, NULL, 16 ); } else i_color = (int) strtol( psz_color, NULL, 0 ); *pi_color = 0; *pi_color |= ( ( i_color & 0x000000FF ) << 16 ); /* Red */ *pi_color |= ( ( i_color & 0x0000FF00 ) ); /* Green */ *pi_color |= ( ( i_color & 0x00FF0000 ) >> 16 ); /* Blue */ if( pi_alpha != NULL ) *pi_alpha = ( i_color & 0xFF000000 ) >> 24;}/***************************************************************************** * ParseSSAHeader: Retrieve global formatting information etc *****************************************************************************/void ParseSSAHeader( decoder_t *p_dec ){ decoder_sys_t *p_sys = p_dec->p_sys; char *psz_parser = NULL; char *psz_header = malloc( p_dec->fmt_in.i_extra+1 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -