Fix decoding of DXSA subtitles.

Message ID 1420629488-25392-1-git-send-email-jb@videolan.org
State New
Headers show

Commit Message

Jean-Baptiste Kempf Jan. 7, 2015, 11:18 a.m.
From: Alexandre Colucci <alexandre@elgato.com>

These have a DXSA tag and contain alpha in addition to
color values for palette.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
---
 libavcodec/xsubdec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch

diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 3d85973..f876d92 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -56,6 +56,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     int w, h, x, y, i;
     int64_t packet_time = 0;
     GetBitContext gb;
+    int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
 
     memset(sub, 0, sizeof(*sub));
 
@@ -108,8 +109,8 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     for (i = 0; i < sub->rects[0]->nb_colors; i++)
         ((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);
     // make all except background (first entry) non-transparent
-    for (i = 1; i < sub->rects[0]->nb_colors; i++)
-        ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= 0xff000000;
+    for (i = 0; i < sub->rects[0]->nb_colors; i++)
+        ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= (has_alpha ? *buf++ : (i ? 0xff : 0)) << 24;
 
     // process RLE-compressed data
     init_get_bits(&gb, buf, (buf_end - buf) * 8);