[MPlayer-dev-eng] [PATCH] advancing subtitle alignment management

Salvatore Falco sfalco at studenti.ing.uniroma1.it
Mon May 31 11:27:11 CEST 2004


Hi all. Another message from me, but this is not spam! (not yet)

This time is a patch to improve subtitle alignment management. It implements
SSA alignment styles; note that alignment for SSA files is not actually
supported, but for SAMI files (which use the same alignment codes) it is.

I am attaching also a 'test' subtitle file, for those who want to have a
preview of this new functionality.

	Best regards, Salvatore Falco
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-------------- next part --------------
diff -Nur MPlayer-20040527.orig/libvo/sub.c MPlayer-20040527/libvo/sub.c
--- MPlayer-20040527.orig/libvo/sub.c	2003-10-27 22:36:29.000000000 +0100
+++ MPlayer-20040527/libvo/sub.c	2004-05-28 12:54:41.000000000 +0200
@@ -653,16 +653,23 @@
 
     y = obj->y;
     
+    obj->alignment = 0;
     switch(vo_sub->alignment) {
-	case SUB_ALIGNMENT_HLEFT:
+	case SUB_ALIGNMENT_BOTTOMLEFT:
+	case SUB_ALIGNMENT_MIDDLELEFT:
+	case SUB_ALIGNMENT_TOPLEFT:
 	    obj->alignment |= 0x1;
 	    break;
-	case SUB_ALIGNMENT_HCENTER:
-	    obj->alignment |= 0x0;
+	case SUB_ALIGNMENT_BOTTOMRIGHT:
+	case SUB_ALIGNMENT_MIDDLERIGHT:
+	case SUB_ALIGNMENT_TOPRIGHT:
+	    obj->alignment |= 0x2;
 	    break;
-	case SUB_ALIGNMENT_HRIGHT:
+	case SUB_ALIGNMENT_BOTTOMCENTER:
+	case SUB_ALIGNMENT_MIDDLECENTER:
+	case SUB_ALIGNMENT_TOPCENTER:
 	default:
-	    obj->alignment |= 0x2;
+	    obj->alignment |= 0x0;
     }
 
     i=j=0;
diff -Nur MPlayer-20040527.orig/subreader.c MPlayer-20040527/subreader.c
--- MPlayer-20040527.orig/subreader.c	2004-05-21 18:02:09.000000000 +0200
+++ MPlayer-20040527/subreader.c	2004-05-28 12:56:45.000000000 +0200
@@ -100,6 +100,7 @@
     int state;
 
     current->lines = current->start = current->end = 0;
+    current->alignment = SUB_ALIGNMENT_BOTTOMCENTER;
     state = 0;
 
     /* read the first line */
@@ -173,7 +174,38 @@
 	    s = strchr (s, '>');
 	    if (s) { s++; state = 3; continue; }
 	    break;
-	case 5: /* get rid of {...} text */
+	case 5: /* get rid of {...} text, but read the alignment code */
+	    if ((*s == '\\') && (*(s + 1) == 'a') && !sub_no_text_pp) {
+		if (stristr(s, "\\a1") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_BOTTOMLEFT;
+		    s = s + 3;
+		}
+		if (stristr(s, "\\a2") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_BOTTOMCENTER;
+		    s = s + 3;
+		} else if (stristr(s, "\\a3") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_BOTTOMRIGHT;
+		    s = s + 3;
+		} else if ((stristr(s, "\\a4") != NULL) || (stristr(s, "\\a5") != NULL) || (stristr(s, "\\a8") != NULL)) {
+		    current->alignment = SUB_ALIGNMENT_TOPLEFT;
+		    s = s + 3;
+		} else if (stristr(s, "\\a6") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_TOPCENTER;
+		    s = s + 3;
+		} else if (stristr(s, "\\a7") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_TOPRIGHT;
+		    s = s + 3;
+		} else if (stristr(s, "\\a9") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_MIDDLELEFT;
+		    s = s + 3;
+		} else if (stristr(s, "\\a10") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_MIDDLECENTER;
+		    s = s + 4;
+		} else if (stristr(s, "\\a11") != NULL) {
+		    current->alignment = SUB_ALIGNMENT_MIDDLERIGHT;
+		    s = s + 4;
+		}
+	    }
 	    if (*s == '}') state = 3;
 	    ++s;
 	    continue;
@@ -889,11 +921,11 @@
 		continue;
 	    }
 	    if (strstr(directive, "JL") != NULL) {
-		current->alignment = SUB_ALIGNMENT_HLEFT;
+		current->alignment = SUB_ALIGNMENT_BOTTOMLEFT;
 	    } else if (strstr(directive, "JR") != NULL) {
-		current->alignment = SUB_ALIGNMENT_HRIGHT;
+		current->alignment = SUB_ALIGNMENT_BOTTOMRIGHT;
 	    } else {
-		current->alignment = SUB_ALIGNMENT_HCENTER;
+		current->alignment = SUB_ALIGNMENT_BOTTOMCENTER;
 	    }
 	    strcpy(line2, line1);
 	    p = line2;
@@ -1317,7 +1349,9 @@
     int n_max, n_first, i, j, sub_first, sub_orig;
     subtitle *first, *second, *sub, *return_sub;
     sub_data *subt_data;
+#ifdef HAVE_ENCA
     char enca_lang[100], enca_fallback[100];
+#endif
     int uses_time = 0, sub_num = 0, sub_errs = 0;
     char *current_sub_cp=NULL;
     struct subreader sr[]=
@@ -1652,7 +1686,7 @@
 	    memset(&second[sub_num], '\0', sizeof(subtitle));
 	    second[sub_num].start = local_start;
 	    second[sub_num].end   = local_end;
-	    second[sub_num].alignment = SUB_ALIGNMENT_HCENTER;
+	    second[sub_num].alignment = first[sub_first].alignment;
 	    n_max = (lines_to_add < SUB_MAX_TEXT) ? lines_to_add : SUB_MAX_TEXT;
 	    for (i = 0, j = 0; j < n_max; ++j) {
 		if (placeholder[counter][j] != -1) {
diff -Nur MPlayer-20040527.orig/subreader.h MPlayer-20040527/subreader.h
--- MPlayer-20040527.orig/subreader.h	2004-05-08 19:52:25.000000000 +0200
+++ MPlayer-20040527/subreader.h	2004-05-28 12:40:29.000000000 +0200
@@ -28,9 +28,15 @@
 #define MAX_SUBTITLE_FILES 128
 
 #define SUB_MAX_TEXT 10
-#define SUB_ALIGNMENT_HLEFT	1
-#define SUB_ALIGNMENT_HCENTER	0
-#define SUB_ALIGNMENT_HRIGHT	2
+#define SUB_ALIGNMENT_BOTTOMLEFT	1
+#define SUB_ALIGNMENT_BOTTOMCENTER	2
+#define SUB_ALIGNMENT_BOTTOMRIGHT	3
+#define SUB_ALIGNMENT_MIDDLELEFT	4
+#define SUB_ALIGNMENT_MIDDLECENTER	5
+#define SUB_ALIGNMENT_MIDDLERIGHT	6
+#define SUB_ALIGNMENT_TOPLEFT		7
+#define SUB_ALIGNMENT_TOPCENTER	8
+#define SUB_ALIGNMENT_TOPRIGHT		9
 
 typedef struct {
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01-alignment.smi
Type: application/smil
Size: 2108 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20040531/023a5ac6/attachment.smi>


More information about the MPlayer-dev-eng mailing list