diff mbox series

[FFmpeg-devel,3/4] avcodec/movtextdec: Perform RGB->BGR color conversion early

Message ID AM7PR03MB66609409B60C827457CC4F008F6E9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit cce2765ce9dee0c653e725282107694ed0ed345a
Headers show
Series [FFmpeg-devel,1/4] avcodec/movtextdec: Rename several structure elements | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 7, 2021, 11:24 p.m. UTC
Reduces the amount of conversions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/movtextdec.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index d3b15d07f8..c50626c0b5 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -144,6 +144,7 @@  static void mov_text_parse_style_record(StyleBox *style, const uint8_t **ptr)
     style->fontsize  = bytestream_get_byte(ptr);
     // Primary color
     style->color     = bytestream_get_be24(ptr);
+    style->color     = RGB_TO_BGR(style->color);
     style->alpha     = bytestream_get_byte(ptr);
 }
 
@@ -189,6 +190,7 @@  static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
     }
     // Background Color
     m->d.back_color = bytestream_get_be24(&tx3g_ptr);
+    m->d.back_color = RGB_TO_BGR(m->d.back_color);
     m->d.back_alpha = bytestream_get_byte(&tx3g_ptr);
     // BoxRecord
     tx3g_ptr += 8;
@@ -369,7 +371,7 @@  static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
                     }
                 if (default_style->color != style->color) {
                     color = style->color;
-                    av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color));
+                    av_bprintf(buf, "{\\1c&H%X&}", color);
                 }
                 if (default_style->alpha != style->alpha)
                     av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha);
@@ -392,10 +394,10 @@  static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
             }
             if (text_pos == m->h.hlit_end) {
                 if (m->box_flags & HCLR_BOX) {
-                    av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(default_style->color));
+                    av_bprintf(buf, "{\\2c&H%X&}", default_style->color);
                 } else {
                     av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}",
-                               RGB_TO_BGR(color), RGB_TO_BGR(default_style->color));
+                               color, default_style->color);
                 }
             }
         }
@@ -441,10 +443,10 @@  static int mov_text_init(AVCodecContext *avctx) {
         return ff_ass_subtitle_header_full(avctx,
                     m->frame_width, m->frame_height,
                     m->d.font, default_style->fontsize,
-                    (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color),
-                    (255U - default_style->alpha) << 24 | RGB_TO_BGR(default_style->color),
-                    (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color),
-                    (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color),
+                    (255U - default_style->alpha) << 24 | default_style->color,
+                    (255U - default_style->alpha) << 24 | default_style->color,
+                    (255U - m->d.back_alpha) << 24 | m->d.back_color,
+                    (255U - m->d.back_alpha) << 24 | m->d.back_color,
                     default_style->bold, default_style->italic, default_style->underline,
                     ASS_DEFAULT_BORDERSTYLE, m->d.alignment);
     } else