summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2012-11-25 17:28:17 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2012-11-25 23:47:57 +0100
commitfea9ea33b2ea4f40b078da691e9009db9407d70a (patch)
tree5bbfe4dfd73b135b2041eb17bfcfb5766c7ac744 /sub
parent2b728da8c8687846f6d6a2dc33c3d5e2879eafa5 (diff)
downloadmpv-fea9ea33b2ea4f40b078da691e9009db9407d70a.tar.bz2
mpv-fea9ea33b2ea4f40b078da691e9009db9407d70a.tar.xz
subassconverter: correctly handle RRGGBB and unknow formats
The following HEX formats are now parsed correctly: `#RRGGBB`, `RRGGBB`. Moreover this implementation doesn't show the HTML on screen if the input color is not recognized. A warning is still displayed in the terminal.
Diffstat (limited to 'sub')
-rw-r--r--sub/subassconvert.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/sub/subassconvert.c b/sub/subassconvert.c
index 09ce94793c..16815696f1 100644
--- a/sub/subassconvert.c
+++ b/sub/subassconvert.c
@@ -231,34 +231,43 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
tag->has_size = true;
has_valid_attr = true;
} else if (!bstrcmp0(attr, "color")) {
- if (bstr_eatstart(&val, bstr0("#"))) {
- // #RRGGBB format
+ int found = 0;
+
+ // Try to lookup the string in standard web colors
+ for (int i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) {
+ char *color = subrip_web_colors[i].s;
+ if (bstrcasecmp(val, bstr0(color)) == 0) {
+ tag->color = subrip_web_colors[i].v;
+ found = 1;
+ }
+ }
+
+ // If it's not a web color it must be a HEX RGB value
+ if (!found) {
+ // Remove the leading '#'
+ bstr_eatstart(&val, bstr0("#"));
+
+ // Parse RRGGBB format
tag->color = bstrtoll(val, &val, 16) & 0x00ffffff;
- if (val.len)
- break;
- tag->color = ((tag->color & 0xff) << 16)
- | (tag->color & 0xff00)
- | ((tag->color & 0xff0000) >> 16);
- } else {
- // Standard web colors
- for (int i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) {
- char *color = subrip_web_colors[i].s;
- if (bstrcasecmp(val, bstr0(color)) == 0) {
- tag->color = subrip_web_colors[i].v;
- goto foundcolor;
- }
+ if (!val.len) {
+ tag->color = ((tag->color & 0xff) << 16)
+ | (tag->color & 0xff00)
+ | ((tag->color & 0xff0000) >> 16);
+ found = 1;
}
+ }
- /* We didn't find any matching color */
+ if (found) {
+ append_text(&new_line, "{\\c&H%06X&}", tag->color);
+ tag->has_color = true;
+ } else {
+ // We didn't find any matching color
mp_tmsg(MSGT_SUBREADER, MSGL_WARN,
- "SubRip: unknown font color in subtitle: %s\n", orig);
+ "SubRip: unknown font color in subtitle: %s\n",
+ orig);
append_text(&new_line, "{\\c}");
- continue;
-
- foundcolor: ;
}
- append_text(&new_line, "{\\c&H%06X&}", tag->color);
- tag->has_color = true;
+
has_valid_attr = true;
} else if (!bstrcmp0(attr, "face")) {
/* Font face attribute */