[MPlayer-cvslog] r19658 - in trunk: cfg-common.h libass/ass.c libass/ass.h libass/ass_mp.c libass/ass_mp.h

eugeni subversion at mplayerhq.hu
Sun Sep 3 19:42:32 CEST 2006


Author: eugeni
Date: Sun Sep  3 19:42:31 2006
New Revision: 19658

Modified:
   trunk/cfg-common.h
   trunk/libass/ass.c
   trunk/libass/ass.h
   trunk/libass/ass_mp.c
   trunk/libass/ass_mp.h

Log:
Add -ass-styles option. It allows to load styles from a file and use them
for plain text subtitles rendering.


Modified: trunk/cfg-common.h
==============================================================================
--- trunk/cfg-common.h	(original)
+++ trunk/cfg-common.h	Sun Sep  3 19:42:31 2006
@@ -318,6 +318,7 @@
 	{"ass-force-style", &ass_force_style_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
 	{"ass-color", &ass_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"ass-border-color", &ass_border_color, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"ass-styles", &ass_styles_file, CONF_TYPE_STRING, 0, 0, 0, NULL},
 #endif
 #ifdef HAVE_FONTCONFIG
 	{"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, 0, 1, NULL},

Modified: trunk/libass/ass.c
==============================================================================
--- trunk/libass/ass.c	(original)
+++ trunk/libass/ass.c	Sun Sep  3 19:42:31 2006
@@ -28,8 +28,10 @@
 
 char *get_path(char *);
 
+typedef enum {PST_UNKNOWN = 0, PST_INFO, PST_STYLES, PST_EVENTS, PST_FONTS} parser_state_t;
+
 struct parser_priv_s {
-	enum {PST_UNKNOWN = 0, PST_INFO, PST_STYLES, PST_EVENTS, PST_FONTS} state;
+	parser_state_t state;
 	char* fontname;
 	char* fontdata;
 	int fontdata_size;
@@ -844,18 +846,15 @@
 #endif // ICONV
 
 /**
- * \brief Read subtitles from file.
- * \param fname file name
- * \return newly allocated track
-*/ 
-ass_track_t* ass_read_file(char* fname)
+ * \brief read file contents into newly allocated buffer, recoding to utf-8
+ */
+static char* read_file(char* fname)
 {
 	int res;
 	long sz;
 	long bytes_read;
 	char* buf;
-	ass_track_t* track;
-	
+
 	FILE* fp = fopen(fname, "rb");
 	if (!fp) {
 		mp_msg(MSGT_GLOBAL, MSGL_WARN, "ass_read_file(%s): fopen failed\n", fname);
@@ -899,11 +898,25 @@
 	if (sub_cp) {
 		char* tmpbuf = sub_recode(buf, sz);
 		free(buf);
-		if (!tmpbuf)
-			return 0;
 		buf = tmpbuf;
 	}
 #endif
+	return buf;
+}
+
+/**
+ * \brief Read subtitles from file.
+ * \param fname file name
+ * \return newly allocated track
+*/ 
+ass_track_t* ass_read_file(char* fname)
+{
+	char* buf;
+	ass_track_t* track;
+	
+	buf = read_file(fname);
+	if (!buf)
+		return 0;
 	
 	track = ass_new_track();
 	track->name = strdup(fname);
@@ -930,6 +943,26 @@
 	return track;
 }
 
+/**
+ * \brief read styles from file into already initialized track
+ */
+int ass_read_styles(ass_track_t* track, char* fname)
+{
+	char* buf;
+	parser_state_t old_state;
+
+	buf = read_file(fname);
+	if (!buf)
+		return 1;
+
+	old_state = track->parser_priv->state;
+	track->parser_priv->state = PST_STYLES;
+	process_text(track, buf);
+	track->parser_priv->state = old_state;
+
+	return 0;
+}
+
 static char* validate_fname(char* name)
 {
 	char* fname;

Modified: trunk/libass/ass.h
==============================================================================
--- trunk/libass/ass.h	(original)
+++ trunk/libass/ass.h	Sun Sep  3 19:42:31 2006
@@ -130,6 +130,12 @@
 ass_track_t* ass_read_file(char* fname);
 
 /**
+ * \brief read styles from file into already initialized track
+ * \return 0 on success
+ */
+int ass_read_styles(ass_track_t* track, char* fname);
+
+/**
  * \brief Process embedded matroska font. Saves it to ~/.mplayer/fonts.
  * \param name attachment name
  * \param data binary font data

Modified: trunk/libass/ass_mp.c
==============================================================================
--- trunk/libass/ass_mp.c	(original)
+++ trunk/libass/ass_mp.c	Sun Sep  3 19:42:31 2006
@@ -19,6 +19,7 @@
 int ass_use_margins = 0;
 char* ass_color = NULL;
 char* ass_border_color = NULL;
+char* ass_styles_file = NULL;
 
 extern int font_fontconfig;
 extern char* font_name;
@@ -30,10 +31,6 @@
 
 ass_track_t* ass_default_track() {
 	ass_track_t* track = ass_new_track();
-	ass_style_t* style;
-	int sid;
-	double fs;
-	uint32_t c1, c2;
 
 	track->track_type = TRACK_TYPE_ASS;
 	track->Timer = 100.;
@@ -41,6 +38,15 @@
 	track->PlayResY = 288;
 	track->WrapStyle = 0;
 
+	if (ass_styles_file)
+		ass_read_styles(track, ass_styles_file);
+
+	if (track->n_styles == 0) {
+	ass_style_t* style;
+	int sid;
+	double fs;
+	uint32_t c1, c2;
+
 	sid = ass_alloc_style(track);
 	style = track->styles + sid;
 	style->Name = strdup("Default");
@@ -71,6 +77,7 @@
 	style->MarginV = 20;
 	style->ScaleX = 1.;
 	style->ScaleY = 1.;
+	}
 
 	return track;
 }

Modified: trunk/libass/ass_mp.h
==============================================================================
--- trunk/libass/ass_mp.h	(original)
+++ trunk/libass/ass_mp.h	Sun Sep  3 19:42:31 2006
@@ -13,6 +13,7 @@
 extern int ass_use_margins;
 extern char* ass_color;
 extern char* ass_border_color;
+extern char* ass_styles_file;
 
 ass_track_t* ass_default_track();
 int ass_process_subtitle(ass_track_t* track, subtitle* sub);



More information about the MPlayer-cvslog mailing list