From 9554d9844121a688a2fb79b2323203602bb08d17 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sun, 25 Oct 2020 03:26:06 +0200 Subject: process_karaoke_effects: give the code a facelist --- libass/ass_parse.c | 88 +++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/libass/ass_parse.c b/libass/ass_parse.c index 3d7afe2..6b05f95 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -972,59 +972,47 @@ void apply_transition_effects(ASS_Renderer *render_priv, ASS_Event *event) */ void process_karaoke_effects(ASS_Renderer *render_priv) { - GlyphInfo *cur, *cur2; - GlyphInfo *s1, *e1; // start and end of the current word - GlyphInfo *s2; // start of the next word - int i; - int timing; // current timing - int tm_start, tm_end; // timings at start and end of the current word - int tm_current; - double dt; - int x; - int x_start, x_end; + int tm_current = render_priv->time - render_priv->state.event->Start; - tm_current = render_priv->time - render_priv->state.event->Start; - timing = 0; - s1 = s2 = 0; - for (i = 0; i <= render_priv->text_info.length; ++i) { - cur = render_priv->text_info.glyphs + i; - if ((i == render_priv->text_info.length) - || (cur->effect_type != EF_NONE)) { - s1 = s2; - s2 = cur; - if (s1) { - e1 = s2 - 1; - tm_start = timing + s1->effect_skip_timing; - tm_end = tm_start + s1->effect_timing; - timing = tm_end; - x_start = 1000000; - x_end = -1000000; - for (cur2 = s1; cur2 <= e1; ++cur2) { - x_start = FFMIN(x_start, d6_to_int(cur2->bbox.x_min + cur2->pos.x)); - x_end = FFMAX(x_end, d6_to_int(cur2->bbox.x_max + cur2->pos.x)); - } + int timing = 0; + GlyphInfo *last_boundary = NULL; + for (int i = 0; i <= render_priv->text_info.length; i++) { + if (i < render_priv->text_info.length && + render_priv->text_info.glyphs[i].effect_type == EF_NONE) + continue; - dt = (tm_current - tm_start); - if ((s1->effect_type == EF_KARAOKE) - || (s1->effect_type == EF_KARAOKE_KO)) { - if (dt >= 0) - x = x_end + 1; - else - x = x_start; - } else if (s1->effect_type == EF_KARAOKE_KF) { - dt /= (tm_end - tm_start); - x = x_start + (x_end - x_start) * dt; - } else { - ass_msg(render_priv->library, MSGL_ERR, - "Unknown effect type"); - continue; - } + GlyphInfo *start = last_boundary; + GlyphInfo *end = render_priv->text_info.glyphs + i; + last_boundary = end; + if (!start) + continue; - for (cur2 = s1; cur2 <= e1; ++cur2) { - cur2->effect_type = s1->effect_type; - cur2->effect_timing = x - d6_to_int(cur2->pos.x); - } - } + int tm_start = timing + start->effect_skip_timing; + int tm_end = tm_start + start->effect_timing; + timing = tm_end; + + int x_start = 1000000; + int x_end = -1000000; + for (GlyphInfo *info = start; info < end; info++) { + x_start = FFMIN(x_start, d6_to_int(info->bbox.x_min + info->pos.x)); + x_end = FFMAX(x_end, d6_to_int(info->bbox.x_max + info->pos.x)); + } + + int x; + if (start->effect_type == EF_KARAOKE || start->effect_type == EF_KARAOKE_KO) { + x = tm_current < tm_start ? x_start : x_end + 1; + } else if (start->effect_type == EF_KARAOKE_KF) { + double dt = (double) (tm_current - tm_start) / (tm_end - tm_start); + x = x_start + (x_end - x_start) * dt; + } else { + ass_msg(render_priv->library, MSGL_ERR, + "Unknown effect type"); + continue; + } + + for (GlyphInfo *info = start; info < end; info++) { + info->effect_type = start->effect_type; + info->effect_timing = x - d6_to_int(info->pos.x); } } } -- cgit v1.2.3