summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2022-10-01 15:09:01 +0200
committerOneric <oneric@oneric.stub>2022-10-14 20:21:09 +0200
commit371aa684cf8027e1f25d1a3341d0b3d374509408 (patch)
tree84cdea2cd5ba3d63c52942905865a62ffde9d17f
parentb7b816a8ea09d26574ba4090b6e1362a59065b66 (diff)
downloadlibass-371aa684cf8027e1f25d1a3341d0b3d374509408.tar.bz2
libass-371aa684cf8027e1f25d1a3341d0b3d374509408.tar.xz
Support SSA's AlphaLevel style field
Procesing of the actual style field emulates VSFilter's behaviour by parsing the inputs the same way and always using 0x80 for shadows. For user supplied style overrides the field is accepted for all script versions and the provided alpha value is applied to all colours, continuing the existing practice of override tags not caring for version-dependent quirks and limitations. Fixes: https://github.com/libass/libass/issues/40
-rw-r--r--libass/ass.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libass/ass.c b/libass/ass.c
index 7c2ccde..e08a76a 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -380,6 +380,16 @@ static int process_event_tail(ASS_Track *track, ASS_Event *event,
return 1;
}
+static void set_style_alpha(ASS_Style *style, int32_t front_alpha, int32_t back_alpha)
+{
+ front_alpha = FFMAX(FFMIN(front_alpha, 0xFF), 0);
+ back_alpha = FFMAX(FFMIN(back_alpha, 0xFF), 0);
+ style->PrimaryColour = (style->PrimaryColour & 0xFFFFFF00) | front_alpha;
+ style->SecondaryColour = (style->SecondaryColour & 0xFFFFFF00) | front_alpha;
+ style->OutlineColour = (style->OutlineColour & 0xFFFFFF00) | front_alpha;
+ style->BackColour = (style->BackColour & 0xFFFFFF00) | back_alpha;
+}
+
/**
* \brief Parse command line style overrides (--ass-force-style option)
* \param track track to apply overrides to
@@ -436,6 +446,9 @@ void ass_process_force_style(ASS_Track *track)
COLORVAL(SecondaryColour)
COLORVAL(OutlineColour)
COLORVAL(BackColour)
+ } else if (ass_strcasecmp(tname, "AlphaLevel") == 0) {
+ int32_t alpha = parse_int_header(token);
+ set_style_alpha(target, alpha, alpha);
FPVAL(FontSize)
INTVAL(Bold)
INTVAL(Italic)
@@ -512,6 +525,8 @@ static int process_style(ASS_Track *track, char *str)
style->ScaleX = 100.;
style->ScaleY = 100.;
+ int32_t ssa_alpha = 0;
+
while (1) {
NEXT(q, tname);
NEXT(p, token);
@@ -527,6 +542,8 @@ static int process_style(ASS_Track *track, char *str)
// this will destroy SSA's TertiaryColour, but i'm not going to use it anyway
if (track->track_type == TRACK_TYPE_SSA)
target->OutlineColour = target->BackColour;
+ } else if (ass_strcasecmp(tname, "AlphaLevel") == 0) {
+ ssa_alpha = parse_int_header(token);
FPVAL(FontSize)
INTVAL(Bold)
INTVAL(Italic)
@@ -554,6 +571,9 @@ static int process_style(ASS_Track *track, char *str)
PARSE_END
}
free(format);
+ // VSF compat: always set BackColour Alpha to 0x80 in SSA
+ if (track->track_type == TRACK_TYPE_SSA)
+ set_style_alpha(style, ssa_alpha, 0x80);
style->ScaleX = FFMAX(style->ScaleX, 0.) / 100.;
style->ScaleY = FFMAX(style->ScaleY, 0.) / 100.;
style->Spacing = FFMAX(style->Spacing, 0.);