summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-07 20:57:45 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-08 21:00:41 +0100
commitcce2765ce9dee0c653e725282107694ed0ed345a (patch)
treed8a6525b7c6cd3a3396841e94b954145431f6253
parent4b2bc0b8fed9fb464b85fe53b8d49b570b0c9c9e (diff)
avcodec/movtextdec: Perform RGB->BGR color conversion early
Reduces the amount of conversions. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/movtextdec.c16
1 files changed, 9 insertions, 7 deletions
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