mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Further tweaks to TTML color parsing.
This commit is contained in:
parent
7974a61476
commit
c60dac7c46
1 changed files with 5 additions and 5 deletions
|
|
@ -88,18 +88,18 @@ import java.util.regex.Pattern;
|
||||||
Assertions.checkArgument(!TextUtils.isEmpty(colorExpression));
|
Assertions.checkArgument(!TextUtils.isEmpty(colorExpression));
|
||||||
colorExpression = colorExpression.replace(" ", "");
|
colorExpression = colorExpression.replace(" ", "");
|
||||||
if (colorExpression.charAt(0) == '#') {
|
if (colorExpression.charAt(0) == '#') {
|
||||||
// Use a long to avoid rollovers on #FFXXXXXX
|
// Parse using Long to avoid failure when the unsigned value exceeds (2^31 - 1).
|
||||||
long color = Long.parseLong(colorExpression.substring(1), 16);
|
int color = (int) Long.parseLong(colorExpression.substring(1), 16);
|
||||||
if (colorExpression.length() == 7) {
|
if (colorExpression.length() == 7) {
|
||||||
// Set the alpha value
|
// Set the alpha value
|
||||||
color |= 0xFF000000L;
|
color |= 0xFF000000;
|
||||||
} else if (colorExpression.length() == 9) {
|
} else if (colorExpression.length() == 9) {
|
||||||
// We have #RRGGBBAA, but we need #AARRGGBB
|
// We have #RRGGBBAA, but we need #AARRGGBB
|
||||||
color = ((color & 0xFF) << 24) | (color >> 8);
|
color = ((color & 0xFF) << 24) | (color >>> 8);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
return (int) color;
|
return color;
|
||||||
} else if (colorExpression.startsWith(RGBA)) {
|
} else if (colorExpression.startsWith(RGBA)) {
|
||||||
Matcher matcher = RGBA_PATTERN.matcher(colorExpression);
|
Matcher matcher = RGBA_PATTERN.matcher(colorExpression);
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue