[MPlayer-dev-eng] A patch for subtitle colors with missing quotation marks

Federico Kereki fkereki at gmail.com
Thu Aug 2 13:01:13 CEST 2012


Hi!

I've come across many subtitles files with constructs such as

1
00:00:04,669 --> 00:00:08,669
<font color=#00ff00>The Closer 7x19</font>
<font color=#00ffff>Last Rites</font>
Original Air Date on July 30, 2012

where the font color is given in hex notation, but without the required
enclosing quotation marks. This isn't allowed, and the viewer gets
something like:

[image: Inline image 1]

This patch allows for these <font> definitions, and now rather shows:

[image: Inline image 2]

I also refactored a "while(...)" loop, substituting a "for(...)" loop
instead.

Best regards,
Federico Kereki



--- subassconvert.original      2012-08-01 22:05:37.609711324 -0300
+++ subassconvert.c     2012-08-01 22:08:23.621333241 -0300
@@ -194,9 +194,8 @@
             int has_valid_attr = 0;

             *tag = tag[-1]; // keep values from previous tag
-            line += 6;

-            while (*line && *line != '>') {
+            for (line += 6; *line && *line != '>'; line++) {
                 if (strncmp(line, "size=\"", 6) == 0) {
                     line += 6;
                     tag->size = strtol(line, &line, 10);
@@ -204,6 +203,19 @@
                         break;
                     append_text(&new_line, "{\\fs%d}", tag->size);
                     has_valid_attr = 1;
+
+                } else if (strncmp(line, "color=#", 7) == 0) {
+                    line += 7;
+                    tag->color = strtol(line, &line, 16) & 0x00ffffff;
+                    tag->color = ((tag->color & 0xff) << 16) |
+                                  (tag->color & 0xff00) |
+                                 ((tag->color & 0xff0000) >> 16) |
+                                 SUBRIP_FLAG_COLOR;
+                    append_text(&new_line, "{\\c&H%06X&}", tag->color &
0xffffff);
+                    has_valid_attr = 1;
+                    if (*line == '>')
+                        break;
+
                 } else if (strncmp(line, "color=\"", 7) == 0) {
                     line += 7;
                     if (*line == '#') {
@@ -244,6 +256,7 @@
                     }
                     append_text(&new_line, "{\\c&H%06X&}", tag->color &
0xffffff);
                     has_valid_attr = 1;
+
                 } else if (strncmp(line, "face=\"", 6) == 0) {
                     /* Font face attribute */
                     int len;
@@ -257,7 +270,6 @@
                     append_text(&new_line, "{\\fn%.*s}",
BSTR_P(tag->face));
                     has_valid_attr = 1;
                 }
-                line++;
             }

             if (!has_valid_attr || *line != '>') { /* Not valid font tag */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 20675 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20120802/ddfa81ba/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 24440 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20120802/ddfa81ba/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: subassconvert.patch
Type: application/octet-stream
Size: 2019 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20120802/ddfa81ba/attachment-0001.obj>


More information about the MPlayer-dev-eng mailing list