diff mbox series

[FFmpeg-devel,08/23] lavc/movtextdec: add color and alpha style tags

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

Checks

Context Check Description
andriy/ffmpeg-patchwork warning Failed to apply patch

Commit Message

John Stebbins April 6, 2020, 5:52 p.m. UTC
---
 libavcodec/movtextdec.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Philip Langdale April 7, 2020, midnight UTC | #1
On Mon, 6 Apr 2020 11:52:03 -0600
John Stebbins <jstebbins@jetheaddev.com> wrote:

> ---
>  libavcodec/movtextdec.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index eb9c7f5755..4d5dcdf5e7 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -76,6 +76,8 @@ typedef struct {
>      uint8_t bold;
>      uint8_t italic;
>      uint8_t underline;
> +    int color;
> +    uint8_t alpha;
>      uint8_t fontsize;
>      uint16_t style_fontID;
>  } StyleBox;
> @@ -329,14 +331,16 @@ static int decode_styl(const uint8_t *tsmb,
> MovTextContext *m, AVPacket *avpkt) m->s_temp->underline =
> !!(m->s_temp->style_flag & STYLE_FLAG_UNDERLINE); tsmb++;
>          m->s_temp->fontsize = AV_RB8(tsmb);
> +        tsmb++;
> +        m->s_temp->color = AV_RB24(tsmb);
> +        tsmb += 3;
> +        m->s_temp->alpha = AV_RB8(tsmb);
> +        tsmb++;
>          av_dynarray_add(&m->s, &m->count_s, m->s_temp);
>          if(!m->s) {
>              mov_text_cleanup(m);
>              return AVERROR(ENOMEM);
>          }
> -        tsmb++;
> -        // text-color-rgba
> -        tsmb += 4;
>      }
>      return 0;
>  }
> @@ -400,6 +404,11 @@ static int text_to_ass(AVBPrint *buf, const char
> *text, const char *text_end, if (m->s[entry]->style_fontID ==
> m->ftab[i]->fontID) av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font);
>                      }
> +                if (m->d.color != m->s[entry]->color)
> +                    av_bprintf(buf, "{\\1c&H%X&}",
> +                               RGB_TO_BGR(m->s[entry]->color));
> +                if (m->d.alpha != m->s[entry]->alpha)
> +                    av_bprintf(buf, "{\\1a&H%02X&}", 255 -
> m->s[entry]->alpha); }
>              if (text_pos == m->s[entry]->style_end) {
>                  if (style_active) {

LGTM.


--phil
diff mbox series

Patch

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index eb9c7f5755..4d5dcdf5e7 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -76,6 +76,8 @@  typedef struct {
     uint8_t bold;
     uint8_t italic;
     uint8_t underline;
+    int color;
+    uint8_t alpha;
     uint8_t fontsize;
     uint16_t style_fontID;
 } StyleBox;
@@ -329,14 +331,16 @@  static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
         m->s_temp->underline = !!(m->s_temp->style_flag & STYLE_FLAG_UNDERLINE);
         tsmb++;
         m->s_temp->fontsize = AV_RB8(tsmb);
+        tsmb++;
+        m->s_temp->color = AV_RB24(tsmb);
+        tsmb += 3;
+        m->s_temp->alpha = AV_RB8(tsmb);
+        tsmb++;
         av_dynarray_add(&m->s, &m->count_s, m->s_temp);
         if(!m->s) {
             mov_text_cleanup(m);
             return AVERROR(ENOMEM);
         }
-        tsmb++;
-        // text-color-rgba
-        tsmb += 4;
     }
     return 0;
 }
@@ -400,6 +404,11 @@  static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
                         if (m->s[entry]->style_fontID == m->ftab[i]->fontID)
                             av_bprintf(buf, "{\\fn%s}", m->ftab[i]->font);
                     }
+                if (m->d.color != m->s[entry]->color)
+                    av_bprintf(buf, "{\\1c&H%X&}",
+                               RGB_TO_BGR(m->s[entry]->color));
+                if (m->d.alpha != m->s[entry]->alpha)
+                    av_bprintf(buf, "{\\1a&H%02X&}", 255 - m->s[entry]->alpha);
             }
             if (text_pos == m->s[entry]->style_end) {
                 if (style_active) {