367
369
int i, r, g, b, a = 0;
368
370
DVBSubContext *ctx = avctx->priv_data;
370
if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
372
if (ctx->substream < 0) {
373
ctx->composition_id = -1;
374
ctx->ancillary_id = -1;
375
} else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
371
376
av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
372
377
ctx->composition_id = -1;
373
378
ctx->ancillary_id = -1;
375
if (avctx->extradata_size > 5) {
376
av_log(avctx, AV_LOG_WARNING, "Decoding first DVB subtitles sub-stream\n");
380
if (avctx->extradata_size > 5*ctx->substream + 2) {
381
ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream);
382
ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2);
384
av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream);
385
ctx->composition_id = AV_RB16(avctx->extradata);
386
ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
379
ctx->composition_id = AV_RB16(avctx->extradata);
380
ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
383
390
ctx->version = -1;
754
761
return pixels_read;
764
static void compute_default_clut(AVPicture *frame, int w, int h)
766
uint8_t list[256] = {0};
767
uint8_t list_inv[256];
768
int counttab[256] = {0};
771
#define V(x,y) frame->data[0][(x) + (y)*frame->linesize[0]]
772
for (y = 0; y<h; y++) {
773
for (x = 0; x<w; x++) {
775
int vl = x ? V(x-1,y) + 1 : 0;
776
int vr = x+1<w ? V(x+1,y) + 1 : 0;
777
int vt = y ? V(x,y-1) + 1 : 0;
778
int vb = y+1<h ? V(x,y+1) + 1 : 0;
779
counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
782
#define L(x,y) list[ frame->data[0][(x) + (y)*frame->linesize[0]] ]
784
for (i = 0; i<256; i++) {
785
int scoretab[256] = {0};
788
for (y = 0; y<h; y++) {
789
for (x = 0; x<w; x++) {
790
int v = frame->data[0][x + y*frame->linesize[0]];
792
int l_l = x ? L(x-1, y) : 1;
793
int l_r = x+1<w ? L(x+1, y) : 1;
794
int l_t = y ? L(x, y-1) : 1;
795
int l_b = y+1<h ? L(x, y+1) : 1;
799
scoretab[v] += l_l + l_r + l_t + l_b;
800
score = 1024LL*scoretab[v] / counttab[v];
801
if (score > bestscore) {
810
list_inv[ i ] = bestv;
814
for (i--; i>=0; i--) {
816
AV_WN32(frame->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
757
821
static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
759
823
DVBSubContext *ctx = avctx->priv_data;
776
840
/* Not touching AVSubtitles again*/
777
841
if(sub->num_rects) {
778
avpriv_request_sample(ctx, "Different Version of Segment asked Twice\n");
842
avpriv_request_sample(ctx, "Different Version of Segment asked Twice");
779
843
return AVERROR_PATCHWELCOME;
781
845
for (display = ctx->display_list; display; display = display->next) {
856
920
memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
922
if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1)
923
compute_default_clut(&rect->pict, rect->w, rect->h);
1025
1092
if (buf + top_field_len + bottom_field_len > buf_end) {
1026
av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
1093
av_log(avctx, AV_LOG_ERROR, "Field data size %d+%d too large\n", top_field_len, bottom_field_len);
1027
1094
return AVERROR_INVALIDDATA;
1108
1175
if (depth == 0) {
1109
1176
av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
1110
return AVERROR_INVALIDDATA;
1113
1179
full_range = (*buf++) & 1;
1607
1674
case DVBSUB_DISPLAYDEFINITION_SEGMENT:
1608
1675
ret = dvbsub_parse_display_definition_segment(avctx, p,
1609
1676
segment_length);
1611
1679
case DVBSUB_DISPLAY_SEGMENT:
1612
1680
ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, data_size);
1681
if (got_segment == 15 && !got_dds && !avctx->width && !avctx->height) {
1682
// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
1684
avctx->height = 576;
1613
1686
got_segment |= 16;
1646
1719
#define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
1647
1720
static const AVOption options[] = {
1648
{"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
1721
{"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
1722
{"compute_clut", "compute clut when not available(-1) or always(1) or never(0)", offsetof(DVBSubContext, compute_clut), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DS},
1723
{"dvb_substream", "", offsetof(DVBSubContext, substream), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
1651
1726
static const AVClass dvbsubdec_class = {