[FFmpeg-cvslog] avcodec/movtextdec: Fix immediately adjacent styles
Andreas Rheinhardt
git at videolan.org
Mon Oct 19 06:37:22 EEST 2020
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sat Oct 17 18:42:54 2020 +0200| [dd80066c9734cf730203c158db985489bb509b99] | committer: Andreas Rheinhardt
avcodec/movtextdec: Fix immediately adjacent styles
The checks for whether a style should be opened/closed at the current
character position are as follows: A variable entry contained the index
of the currently active or potentially next active style. If the current
character position coincided with the start of style[entry], the style
was activated; this was followed by a check whether the current
character position coincided with the end of style[entry]; if so, the
style was deactivated and entry incremented. Afterwards the char was
processed.
The order of the checks leads to problems in case the endChar of style A
coincides with the startChar of the next style (say B): Style B was never
opened. When we are at said common position, the currently active style
is A and so the start pos check does not succeed; but the end pos check
does and it closes the currently active style A and increments entry.
At the next iteration of the loop, the current character position is
bigger than the start position of style B (which is style[entry]) and
therefore the style is not activated.
The solution is of course to first check for whether a style needs to be
closed (and increment entry if it does) before checking whether the next
style needs to be opened.
Reviewed-by: Philip Langdale <philipl at overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dd80066c9734cf730203c158db985489bb509b99
---
libavcodec/movtextdec.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index d167eddea5..d46d64b6f2 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -373,7 +373,16 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
if ((m->box_flags & STYL_BOX) && entry < m->style_entries) {
const StyleBox *style = &m->s[entry];
- if (text_pos == style->style_start) {
+ if (text_pos == style->style_end) {
+ if (style_active) {
+ av_bprintf(buf, "{\\r}");
+ style_active = 0;
+ color = m->d.color;
+ }
+ entry++;
+ style++;
+ }
+ if (entry < m->style_entries && text_pos == style->style_start) {
style_active = 1;
if (style->bold ^ m->d.bold)
av_bprintf(buf, "{\\b%d}", style->bold);
@@ -395,14 +404,6 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
if (m->d.alpha != style->alpha)
av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha);
}
- if (text_pos == style->style_end) {
- if (style_active) {
- av_bprintf(buf, "{\\r}");
- style_active = 0;
- color = m->d.color;
- }
- entry++;
- }
}
if (m->box_flags & HLIT_BOX) {
if (text_pos == m->h.hlit_start) {
More information about the ffmpeg-cvslog
mailing list