diff mbox series

[FFmpeg-devel,04/23] lavc/movtextdec: handle changes to default style flags

Message ID 20200406175218.1299994-5-jstebbins@jetheaddev.com
State Accepted
Commit d3c012ff4289e82d0b8ba67b8405cd8258b73d1e
Headers show
Series [FFmpeg-devel,01/23] lavc/movtextdec: fix ass header colors | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

John Stebbins April 6, 2020, 5:51 p.m. UTC
Style flags were only being turned on.  If the default was on and style
record turned off, style flag remained on.
---
 libavcodec/movtextdec.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

Philip Langdale April 6, 2020, 9:49 p.m. UTC | #1
On Mon, 6 Apr 2020 11:51:59 -0600
John Stebbins <jstebbins@jetheaddev.com> wrote:

> Style flags were only being turned on.  If the default was on and
> style record turned off, style flag remained on.
> ---
>  libavcodec/movtextdec.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index d6896562c2..a3e37d013d 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -55,9 +55,9 @@ typedef struct {
>      int fontsize;
>      int color;
>      int back_color;
> -    int bold;
> -    int italic;
> -    int underline;
> +    uint8_t bold;
> +    uint8_t italic;
> +    uint8_t underline;
>      int alignment;
>  } MovTextDefault;
>  
> @@ -70,6 +70,9 @@ typedef struct {
>      uint16_t style_start;
>      uint16_t style_end;
>      uint8_t style_flag;
> +    uint8_t bold;
> +    uint8_t italic;
> +    uint8_t underline;
>      uint8_t fontsize;
>      uint16_t style_fontID;
>  } StyleBox;
> @@ -313,6 +316,9 @@ static int decode_styl(const uint8_t *tsmb,
> MovTextContext *m, AVPacket *avpkt) m->s_temp->style_fontID =
> AV_RB16(tsmb); tsmb += 2;
>          m->s_temp->style_flag = AV_RB8(tsmb);
> +        m->s_temp->bold = !!(m->s_temp->style_flag &
> STYLE_FLAG_BOLD);
> +        m->s_temp->italic = !!(m->s_temp->style_flag &
> STYLE_FLAG_ITALIC);
> +        m->s_temp->underline = !!(m->s_temp->style_flag &
> STYLE_FLAG_UNDERLINE); tsmb++;
>          m->s_temp->fontsize = AV_RB8(tsmb);
>          av_dynarray_add(&m->s, &m->count_s, m->s_temp);
> @@ -373,12 +379,12 @@ static int text_to_ass(AVBPrint *buf, const
> char *text, const char *text_end, if ((m->box_flags & STYL_BOX) &&
> entry < m->style_entries) { if (text_pos == m->s[entry]->style_start)
> { style_active = 1;
> -                if (m->s[entry]->style_flag & STYLE_FLAG_BOLD)
> -                    av_bprintf(buf, "{\\b1}");
> -                if (m->s[entry]->style_flag & STYLE_FLAG_ITALIC)
> -                    av_bprintf(buf, "{\\i1}");
> -                if (m->s[entry]->style_flag & STYLE_FLAG_UNDERLINE)
> -                    av_bprintf(buf, "{\\u1}");
> +                if (m->s[entry]->bold ^ m->d.bold)
> +                    av_bprintf(buf, "{\\b%d}", m->s[entry]->bold);
> +                if (m->s[entry]->italic ^ m->d.italic)
> +                    av_bprintf(buf, "{\\i%d}", m->s[entry]->italic);
> +                if (m->s[entry]->underline ^ m->d.underline)
> +                    av_bprintf(buf, "{\\u%d}",
> m->s[entry]->underline); av_bprintf(buf, "{\\fs%d}",
> m->s[entry]->fontsize); for (i = 0; i < m->ftab_entries; i++) {
>                      if (m->s[entry]->style_fontID ==
> m->ftab[i]->fontID)

LGTM.


--phil
diff mbox series

Patch

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index d6896562c2..a3e37d013d 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -55,9 +55,9 @@  typedef struct {
     int fontsize;
     int color;
     int back_color;
-    int bold;
-    int italic;
-    int underline;
+    uint8_t bold;
+    uint8_t italic;
+    uint8_t underline;
     int alignment;
 } MovTextDefault;
 
@@ -70,6 +70,9 @@  typedef struct {
     uint16_t style_start;
     uint16_t style_end;
     uint8_t style_flag;
+    uint8_t bold;
+    uint8_t italic;
+    uint8_t underline;
     uint8_t fontsize;
     uint16_t style_fontID;
 } StyleBox;
@@ -313,6 +316,9 @@  static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
         m->s_temp->style_fontID = AV_RB16(tsmb);
         tsmb += 2;
         m->s_temp->style_flag = AV_RB8(tsmb);
+        m->s_temp->bold = !!(m->s_temp->style_flag & STYLE_FLAG_BOLD);
+        m->s_temp->italic = !!(m->s_temp->style_flag & STYLE_FLAG_ITALIC);
+        m->s_temp->underline = !!(m->s_temp->style_flag & STYLE_FLAG_UNDERLINE);
         tsmb++;
         m->s_temp->fontsize = AV_RB8(tsmb);
         av_dynarray_add(&m->s, &m->count_s, m->s_temp);
@@ -373,12 +379,12 @@  static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
         if ((m->box_flags & STYL_BOX) && entry < m->style_entries) {
             if (text_pos == m->s[entry]->style_start) {
                 style_active = 1;
-                if (m->s[entry]->style_flag & STYLE_FLAG_BOLD)
-                    av_bprintf(buf, "{\\b1}");
-                if (m->s[entry]->style_flag & STYLE_FLAG_ITALIC)
-                    av_bprintf(buf, "{\\i1}");
-                if (m->s[entry]->style_flag & STYLE_FLAG_UNDERLINE)
-                    av_bprintf(buf, "{\\u1}");
+                if (m->s[entry]->bold ^ m->d.bold)
+                    av_bprintf(buf, "{\\b%d}", m->s[entry]->bold);
+                if (m->s[entry]->italic ^ m->d.italic)
+                    av_bprintf(buf, "{\\i%d}", m->s[entry]->italic);
+                if (m->s[entry]->underline ^ m->d.underline)
+                    av_bprintf(buf, "{\\u%d}", m->s[entry]->underline);
                 av_bprintf(buf, "{\\fs%d}", m->s[entry]->fontsize);
                 for (i = 0; i < m->ftab_entries; i++) {
                     if (m->s[entry]->style_fontID == m->ftab[i]->fontID)