summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2009-08-12 06:20:26 +0200
committerGrigori Goronzy <greg@blackbox>2009-08-12 06:20:26 +0200
commit8a9ef5e2014068a348cb3e0f965113a827d93cd7 (patch)
treee94067b5011b2b4ce251dc5f2348022667fd3eb6
parente8032bc820dd0079db103165cf3d4d84f429edb7 (diff)
downloadlibass-8a9ef5e2014068a348cb3e0f965113a827d93cd7.tar.bz2
libass-8a9ef5e2014068a348cb3e0f965113a827d93cd7.tar.xz
Always parse colors as hex for ASS tracks
According to the ASS specification, colors can only be specified in hex. Modify the color parsing accordingly; this especially means that colors where the hex sigil (the "H") is missing can now be parsed.
-rw-r--r--libass/ass.c2
-rw-r--r--libass/ass_render.c9
-rw-r--r--libass/ass_utils.c5
-rw-r--r--libass/ass_utils.h2
4 files changed, 11 insertions, 7 deletions
diff --git a/libass/ass.c b/libass/ass.c
index 6c28a97..057a6e3 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -198,7 +198,7 @@ static int lookup_style(ASS_Track *track, char *name)
static uint32_t string2color(ASS_Library *library, char *p)
{
uint32_t tmp;
- (void) strtocolor(library, &p, &tmp);
+ (void) strtocolor(library, &p, &tmp, 0);
return tmp;
}
diff --git a/libass/ass_render.c b/libass/ass_render.c
index f5ed87b..aa67727 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -1260,7 +1260,8 @@ static char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr)
} else if (mystrcmp(&p, "alpha")) {
uint32_t val;
int i;
- if (strtocolor(render_priv->library, &p, &val)) {
+ int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
+ if (strtocolor(render_priv->library, &p, &val, hex)) {
unsigned char a = val >> 24;
for (i = 0; i < 4; ++i)
change_alpha(&render_priv->state.c[i], a, pwr);
@@ -1449,7 +1450,8 @@ static char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr)
}
} else if (mystrcmp(&p, "c")) {
uint32_t val;
- if (!strtocolor(render_priv->library, &p, &val))
+ int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
+ if (!strtocolor(render_priv->library, &p, &val, hex))
val = render_priv->state.style->PrimaryColour;
ass_msg(render_priv->library, MSGL_DBG2, "color: %X", val);
change_color(&render_priv->state.c[0], val, pwr);
@@ -1459,8 +1461,9 @@ static char *parse_tag(ASS_Renderer *render_priv, char *p, double pwr)
int cidx = n - '1';
char cmd = *(p - 1);
uint32_t val;
+ int hex = render_priv->track->track_type == TRACK_TYPE_ASS;
assert((n >= '1') && (n <= '4'));
- if (!strtocolor(render_priv->library, &p, &val))
+ if (!strtocolor(render_priv->library, &p, &val, hex))
switch (n) {
case '1':
val = render_priv->state.style->PrimaryColour;
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index e8fce67..6ca78b8 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -74,11 +74,12 @@ int mystrtod(char **p, double *res)
return 0;
}
-int strtocolor(ASS_Library *library, char **q, uint32_t *res)
+int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex)
{
uint32_t color = 0;
int result;
char *p = *q;
+ int base = hex ? 16 : 10;
if (*p == '&')
++p;
@@ -89,7 +90,7 @@ int strtocolor(ASS_Library *library, char **q, uint32_t *res)
++p;
result = mystrtou32(&p, 16, &color);
} else {
- result = mystrtou32(&p, 0, &color);
+ result = mystrtou32(&p, base, &color);
}
{
diff --git a/libass/ass_utils.h b/libass/ass_utils.h
index 8590bb4..bade578 100644
--- a/libass/ass_utils.h
+++ b/libass/ass_utils.h
@@ -49,7 +49,7 @@ int mystrtoi(char **p, int *res);
int mystrtoll(char **p, long long *res);
int mystrtou32(char **p, int base, uint32_t *res);
int mystrtod(char **p, double *res);
-int strtocolor(ASS_Library *library, char **q, uint32_t *res);
+int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex);
char parse_bool(char *str);
unsigned ass_utf8_get_char(char **str);
void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...);