Browse Source

xsub: Support DXSA subtitles

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

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
tags/n2.6
Alexandre Colucci Luca Barbato 10 years ago
parent
commit
5a1addd7c1
1 changed files with 11 additions and 4 deletions
  1. +11
    -4
      libavcodec/xsubdec.c

+ 11
- 4
libavcodec/xsubdec.c View File

@@ -56,11 +56,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int w, h, x, y, i; int w, h, x, y, i;
int64_t packet_time = 0; int64_t packet_time = 0;
GetBitContext gb; GetBitContext gb;
int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');


memset(sub, 0, sizeof(*sub)); memset(sub, 0, sizeof(*sub));


// check that at least header fits // check that at least header fits
if (buf_size < 27 + 7 * 2 + 4 * 3) {
if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
return -1; return -1;
} }
@@ -107,9 +108,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
// read palette // read palette
for (i = 0; i < sub->rects[0]->nb_colors; i++) for (i = 0; i < sub->rects[0]->nb_colors; i++)
((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf); ((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;

if (!has_alpha) {
// 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;
} else {
for (i = 0; i < sub->rects[0]->nb_colors; i++)
((uint32_t *)sub->rects[0]->pict.data[1])[i] |= *buf++ << 24;
}


// process RLE-compressed data // process RLE-compressed data
init_get_bits(&gb, buf, (buf_end - buf) * 8); init_get_bits(&gb, buf, (buf_end - buf) * 8);


Loading…
Cancel
Save