History

Merge commit 'a17a7661906ba295d67afd80ac0770422e1b02b3'

* commit 'a17a7661906ba295d67afd80ac0770422e1b02b3': lavc: Add data and linesize to AVSubtitleRect

Hendrik Leppkes committed 11 years ago

Commit ee573b42 parents 37498a4 a17a76611 files · +183 −86Browse files

Unified · Split

11 files
  1. doc/APIchanges +4 −0
  2. libavcodec/avcodec.h +11 −2
  3. libavcodec/dvbsub.c +3 −3
  4. libavcodec/dvbsubdec.c +25 −16
  5. libavcodec/dvdsubdec.c +41 −20
  6. libavcodec/dvdsubenc.c +29 −14
  7. libavcodec/pgssubdec.c +19 −8
  8. libavcodec/utils.c +4 −4
  9. libavcodec/version.h +4 −1
  10. libavcodec/xsubdec.c +23 −11
  11. libavcodec/xsubenc.c +20 −7
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182015-10-22 - xxxxxxx - lavc 57.9.100 / lavc 57.5.0 - avcodec.h
19 Add data and linesize array to AVSubtitleRect, to be used instead of
20 the ones from the embedded AVPicture.
21
182015-10-22 - xxxxxxx - lavc 57.8.100 / lavc 57.0.0 - qsv.h222015-10-22 - xxxxxxx - lavc 57.8.100 / lavc 57.0.0 - qsv.h
19 Add an API for allocating opaque surfaces.23 Add an API for allocating opaque surfaces.
20 24
libavcodec/avcodec.h+11−2
@@ -3618,11 +3618,20 @@ typedef struct AVSubtitleRect { · 3617 unmodified lines
3618 int h; ///< height of pict, undefined when pict is not set3618 int h; ///< height of pict, undefined when pict is not set
3619 int nb_colors; ///< number of colors in pict, undefined when pict is not set3619 int nb_colors; ///< number of colors in pict, undefined when pict is not set
3620 3620
3621#if FF_API_AVPICTURE
3621 /**3622 /**
3622 * data+linesize for the bitmap of this subtitle.3623 * @deprecated unused
3623 * can be set for text/ass as well once they are rendered
3624 */3624 */
3625 attribute_deprecated
3625 AVPicture pict;3626 AVPicture pict;
3627#endif
3628 /**
3629 * data+linesize for the bitmap of this subtitle.
3630 * Can be set for text/ass as well once they are rendered.
3631 */
3632 uint8_t *data[4];
3633 int linesize[4];
3634
3626 enum AVSubtitleType type;3635 enum AVSubtitleType type;
3627 3636
3628 char *text; ///< 0 terminated plain UTF-8 text3637 char *text; ///< 0 terminated plain UTF-8 text
libavcodec/dvbsub.c+3−3
@@ -315,7 +315,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, · 314 unmodified lines
315 *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */315 *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
316 {316 {
317 int a, r, g, b;317 int a, r, g, b;
318 uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i];318 uint32_t x= ((uint32_t*)h->rects[clut_id]->data[1])[i];
319 a = (x >> 24) & 0xff;319 a = (x >> 24) & 0xff;
320 r = (x >> 16) & 0xff;320 r = (x >> 16) & 0xff;
321 g = (x >> 8) & 0xff;321 g = (x >> 8) & 0xff;
@@ -410,10 +410,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, · 88 unmodified lines
410 q += 2;410 q += 2;
411 411
412 top_ptr = q;412 top_ptr = q;
413 dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2,413 dvb_encode_rle(&q, h->rects[object_id]->data[0], h->rects[object_id]->w * 2,
414 h->rects[object_id]->w, h->rects[object_id]->h >> 1);414 h->rects[object_id]->w, h->rects[object_id]->h >> 1);
415 bottom_ptr = q;415 bottom_ptr = q;
416 dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,416 dvb_encode_rle(&q, h->rects[object_id]->data[0] + h->rects[object_id]->w,
417 h->rects[object_id]->w * 2, h->rects[object_id]->w,417 h->rects[object_id]->w * 2, h->rects[object_id]->w,
418 h->rects[object_id]->h >> 1);418 h->rects[object_id]->h >> 1);
419 419
libavcodec/dvbsubdec.c+25−16
@@ -761,14 +761,14 @@ static int dvbsub_read_8bit_string(AVCodecContext *avctx, · 760 unmodified lines
761 return pixels_read;761 return pixels_read;
762}762}
763 763
764static void compute_default_clut(AVPicture *frame, int w, int h)764static void compute_default_clut(AVSubtitleRect *rect, int w, int h)
765{765{
766 uint8_t list[256] = {0};766 uint8_t list[256] = {0};
767 uint8_t list_inv[256];767 uint8_t list_inv[256];
768 int counttab[256] = {0};768 int counttab[256] = {0};
769 int count, i, x, y;769 int count, i, x, y;
770 770
771#define V(x,y) frame->data[0][(x) + (y)*frame->linesize[0]]771#define V(x,y) rect->data[0][(x) + (y)*rect->linesize[0]]
772 for (y = 0; y<h; y++) {772 for (y = 0; y<h; y++) {
773 for (x = 0; x<w; x++) {773 for (x = 0; x<w; x++) {
774 int v = V(x,y) + 1;774 int v = V(x,y) + 1;
@@ -779,7 +779,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) · 4 unmodified lines
779 counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));779 counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
780 }780 }
781 }781 }
782#define L(x,y) list[ frame->data[0][(x) + (y)*frame->linesize[0]] ]782#define L(x,y) list[ rect->data[0][(x) + (y)*rect->linesize[0]] ]
783 783
784 for (i = 0; i<256; i++) {784 for (i = 0; i<256; i++) {
785 int scoretab[256] = {0};785 int scoretab[256] = {0};
@@ -787,7 +787,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) · 1 unmodified line
787 int bestv = 0;787 int bestv = 0;
788 for (y = 0; y<h; y++) {788 for (y = 0; y<h; y++) {
789 for (x = 0; x<w; x++) {789 for (x = 0; x<w; x++) {
790 int v = frame->data[0][x + y*frame->linesize[0]];790 int v = rect->data[0][x + y*rect->linesize[0]];
791 int l_m = list[v];791 int l_m = list[v];
792 int l_l = x ? L(x-1, y) : 1;792 int l_l = x ? L(x-1, y) : 1;
793 int l_r = x+1<w ? L(x+1, y) : 1;793 int l_r = x+1<w ? L(x+1, y) : 1;
@@ -813,7 +813,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) · 19 unmodified lines
813 count = i - 1;813 count = i - 1;
814 for (i--; i>=0; i--) {814 for (i--; i>=0; i--) {
815 int v = i*255/count;815 int v = i*255/count;
816 AV_WN32(frame->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));816 AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
817 }817 }
818}818}
819 819
@@ -827,7 +827,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou · 7 unmodified lines
827 AVSubtitleRect *rect;827 AVSubtitleRect *rect;
828 DVBSubCLUT *clut;828 DVBSubCLUT *clut;
829 uint32_t *clut_table;829 uint32_t *clut_table;
830 int i;830 int i,j;
831 int offset_x=0, offset_y=0;831 int offset_x=0, offset_y=0;
832 int ret = 0;832 int ret = 0;
833 833
@@ -884,7 +884,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou · 50 unmodified lines
884 rect->h = region->height;884 rect->h = region->height;
885 rect->nb_colors = (1 << region->depth);885 rect->nb_colors = (1 << region->depth);
886 rect->type = SUBTITLE_BITMAP;886 rect->type = SUBTITLE_BITMAP;
887 rect->pict.linesize[0] = region->width;887 rect->linesize[0] = region->width;
888 888
889 clut = get_clut(ctx, region->clut);889 clut = get_clut(ctx, region->clut);
890 890
@@ -904,23 +904,32 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou · 13 unmodified lines
904 break;904 break;
905 }905 }
906 906
907 rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);907 rect->data[1] = av_mallocz(AVPALETTE_SIZE);
908 if (!rect->pict.data[1]) {908 if (!rect->data[1]) {
909 ret = AVERROR(ENOMEM);909 ret = AVERROR(ENOMEM);
910 goto fail;910 goto fail;
911 }911 }
912 memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));912 memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
913 913
914 rect->pict.data[0] = av_malloc(region->buf_size);914 rect->data[0] = av_malloc(region->buf_size);
915 if (!rect->pict.data[0]) {915 if (!rect->data[0]) {
916 ret = AVERROR(ENOMEM);916 ret = AVERROR(ENOMEM);
917 goto fail;917 goto fail;
918 }918 }
919 919
920 memcpy(rect->pict.data[0], region->pbuf, region->buf_size);920 memcpy(rect->data[0], region->pbuf, region->buf_size);
921 921
922 if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1)922 if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1)
923 compute_default_clut(&rect->pict, rect->w, rect->h);923 compute_default_clut(rect, rect->w, rect->h);
924
925#if FF_API_AVPICTURE
926FF_DISABLE_DEPRECATION_WARNINGS
927 for (j = 0; j < 4; j++) {
928 rect->pict.data[j] = rect->data[j];
929 rect->pict.linesize[j] = rect->linesize[j];
930 }
931FF_ENABLE_DEPRECATION_WARNINGS
932#endif
924 933
925 i++;934 i++;
926 }935 }
@@ -932,8 +941,8 @@ fail: · 5 unmodified lines
932 for(i=0; i<sub->num_rects; i++) {941 for(i=0; i<sub->num_rects; i++) {
933 rect = sub->rects[i];942 rect = sub->rects[i];
934 if (rect) {943 if (rect) {
935 av_freep(&rect->pict.data[0]);944 av_freep(&rect->data[0]);
936 av_freep(&rect->pict.data[1]);945 av_freep(&rect->data[1]);
937 }946 }
938 av_freep(&sub->rects[i]);947 av_freep(&sub->rects[i]);
939 }948 }
libavcodec/dvdsubdec.c+41−20
@@ -206,8 +206,8 @@ static void reset_rects(AVSubtitle *sub_header) · 205 unmodified lines
206 206
207 if (sub_header->rects) {207 if (sub_header->rects) {
208 for (i = 0; i < sub_header->num_rects; i++) {208 for (i = 0; i < sub_header->num_rects; i++) {
209 av_freep(&sub_header->rects[i]->pict.data[0]);209 av_freep(&sub_header->rects[i]->data[0]);
210 av_freep(&sub_header->rects[i]->pict.data[1]);210 av_freep(&sub_header->rects[i]->data[1]);
211 av_freep(&sub_header->rects[i]);211 av_freep(&sub_header->rects[i]);
212 }212 }
213 av_freep(&sub_header->rects);213 av_freep(&sub_header->rects);
@@ -374,7 +374,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, · 160 unmodified lines
374 if (!sub_header->rects[0])374 if (!sub_header->rects[0])
375 goto fail;375 goto fail;
376 sub_header->num_rects = 1;376 sub_header->num_rects = 1;
377 bitmap = sub_header->rects[0]->pict.data[0] = av_malloc(w * h);377 bitmap = sub_header->rects[0]->data[0] = av_malloc(w * h);
378 if (!bitmap)378 if (!bitmap)
379 goto fail;379 goto fail;
380 if (decode_rle(bitmap, w * 2, w, (h + 1) / 2,380 if (decode_rle(bitmap, w * 2, w, (h + 1) / 2,
@@ -383,17 +383,19 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, · 2 unmodified lines
383 if (decode_rle(bitmap + w, w * 2, w, h / 2,383 if (decode_rle(bitmap + w, w * 2, w, h / 2,
384 buf, offset2, buf_size, is_8bit) < 0)384 buf, offset2, buf_size, is_8bit) < 0)
385 goto fail;385 goto fail;
386 sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);386 sub_header->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE);
387 if (!sub_header->rects[0]->pict.data[1])387 if (!sub_header->rects[0]->data[1])
388 goto fail;388 goto fail;
389 if (is_8bit) {389 if (is_8bit) {
390 if (!yuv_palette)390 if (!yuv_palette)
391 goto fail;391 goto fail;
392 sub_header->rects[0]->nb_colors = 256;392 sub_header->rects[0]->nb_colors = 256;
393 yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);393 yuv_a_to_rgba(yuv_palette, alpha,
394 (uint32_t *)sub_header->rects[0]->data[1],
395 256);
394 } else {396 } else {
395 sub_header->rects[0]->nb_colors = 4;397 sub_header->rects[0]->nb_colors = 4;
396 guess_palette(ctx, (uint32_t*)sub_header->rects[0]->pict.data[1],398 guess_palette(ctx, (uint32_t*)sub_header->rects[0]->data[1],
397 0xffff00);399 0xffff00);
398 }400 }
399 sub_header->rects[0]->x = x1;401 sub_header->rects[0]->x = x1;
@@ -401,8 +403,17 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, · 1 unmodified line
401 sub_header->rects[0]->w = w;403 sub_header->rects[0]->w = w;
402 sub_header->rects[0]->h = h;404 sub_header->rects[0]->h = h;
403 sub_header->rects[0]->type = SUBTITLE_BITMAP;405 sub_header->rects[0]->type = SUBTITLE_BITMAP;
404 sub_header->rects[0]->pict.linesize[0] = w;406 sub_header->rects[0]->linesize[0] = w;
405 sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0;407 sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0;
408
409#if FF_API_AVPICTURE
410FF_DISABLE_DEPRECATION_WARNINGS
411 for (i = 0; i < 4; i++) {
412 sub_header->rects[0]->pict.data[i] = sub_header->rects[0]->data[i];
413 sub_header->rects[0]->pict.linesize[i] = sub_header->rects[0]->linesize[i];
414 }
415FF_ENABLE_DEPRECATION_WARNINGS
416#endif
406 }417 }
407 }418 }
408 if (next_cmd_pos < cmd_pos) {419 if (next_cmd_pos < cmd_pos) {
@@ -443,29 +454,29 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) · 34 unmodified lines
443 return 0;454 return 0;
444 455
445 for(i = 0; i < s->rects[0]->nb_colors; i++) {456 for(i = 0; i < s->rects[0]->nb_colors; i++) {
446 if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)457 if ((((uint32_t *)s->rects[0]->data[1])[i] >> 24) == 0)
447 transp_color[i] = 1;458 transp_color[i] = 1;
448 }459 }
449 y1 = 0;460 y1 = 0;
450 while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],461 while (y1 < s->rects[0]->h && is_transp(s->rects[0]->data[0] + y1 * s->rects[0]->linesize[0],
451 1, s->rects[0]->w, transp_color))462 1, s->rects[0]->w, transp_color))
452 y1++;463 y1++;
453 if (y1 == s->rects[0]->h) {464 if (y1 == s->rects[0]->h) {
454 av_freep(&s->rects[0]->pict.data[0]);465 av_freep(&s->rects[0]->data[0]);
455 s->rects[0]->w = s->rects[0]->h = 0;466 s->rects[0]->w = s->rects[0]->h = 0;
456 return 0;467 return 0;
457 }468 }
458 469
459 y2 = s->rects[0]->h - 1;470 y2 = s->rects[0]->h - 1;
460 while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,471 while (y2 > 0 && is_transp(s->rects[0]->data[0] + y2 * s->rects[0]->linesize[0], 1,
461 s->rects[0]->w, transp_color))472 s->rects[0]->w, transp_color))
462 y2--;473 y2--;
463 x1 = 0;474 x1 = 0;
464 while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],475 while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->data[0] + x1, s->rects[0]->linesize[0],
465 s->rects[0]->h, transp_color))476 s->rects[0]->h, transp_color))
466 x1++;477 x1++;
467 x2 = s->rects[0]->w - 1;478 x2 = s->rects[0]->w - 1;
468 while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,479 while (x2 > 0 && is_transp(s->rects[0]->data[0] + x2, s->rects[0]->linesize[0], s->rects[0]->h,
469 transp_color))480 transp_color))
470 x2--;481 x2--;
471 w = x2 - x1 + 1;482 w = x2 - x1 + 1;
@@ -474,15 +485,25 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) · 2 unmodified lines
474 if (!bitmap)485 if (!bitmap)
475 return 1;486 return 1;
476 for(y = 0; y < h; y++) {487 for(y = 0; y < h; y++) {
477 memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);488 memcpy(bitmap + w * y, s->rects[0]->data[0] + x1 + (y1 + y) * s->rects[0]->linesize[0], w);
478 }489 }
479 av_freep(&s->rects[0]->pict.data[0]);490 av_freep(&s->rects[0]->data[0]);
480 s->rects[0]->pict.data[0] = bitmap;491 s->rects[0]->data[0] = bitmap;
481 s->rects[0]->pict.linesize[0] = w;492 s->rects[0]->linesize[0] = w;
482 s->rects[0]->w = w;493 s->rects[0]->w = w;
483 s->rects[0]->h = h;494 s->rects[0]->h = h;
484 s->rects[0]->x += x1;495 s->rects[0]->x += x1;
485 s->rects[0]->y += y1;496 s->rects[0]->y += y1;
497
498#if FF_API_AVPICTURE
499FF_DISABLE_DEPRECATION_WARNINGS
500 for (i = 0; i < 4; i++) {
501 s->rects[0]->pict.data[i] = s->rects[0]->data[i];
502 s->rects[0]->pict.linesize[i] = s->rects[0]->linesize[i];
503 }
504FF_ENABLE_DEPRECATION_WARNINGS
505#endif
506
486 return 1;507 return 1;
487}508}
488 509
@@ -583,8 +604,8 @@ static int dvdsub_decode(AVCodecContext *avctx, · 94 unmodified lines
583 ff_dlog(NULL, "start=%d ms end =%d ms\n",604 ff_dlog(NULL, "start=%d ms end =%d ms\n",
584 sub->start_display_time,605 sub->start_display_time,
585 sub->end_display_time);606 sub->end_display_time);
586 ppm_save(ppm_name, sub->rects[0]->pict.data[0],607 ppm_save(ppm_name, sub->rects[0]->data[0],
587 sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]);608 sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->data[1]);
588 }609 }
589#endif610#endif
590 611
libavcodec/dvdsubenc.c+29−14
@@ -118,15 +118,15 @@ static void count_colors(AVCodecContext *avctx, unsigned hits[33], · 117 unmodified lines
118{118{
119 DVDSubtitleContext *dvdc = avctx->priv_data;119 DVDSubtitleContext *dvdc = avctx->priv_data;
120 unsigned count[256] = { 0 };120 unsigned count[256] = { 0 };
121 uint32_t *palette = (uint32_t *)r->pict.data[1];121 uint32_t *palette = (uint32_t *)r->data[1];
122 uint32_t color;122 uint32_t color;
123 int x, y, i, j, match, d, best_d, av_uninit(best_j);123 int x, y, i, j, match, d, best_d, av_uninit(best_j);
124 uint8_t *p = r->pict.data[0];124 uint8_t *p = r->data[0];
125 125
126 for (y = 0; y < r->h; y++) {126 for (y = 0; y < r->h; y++) {
127 for (x = 0; x < r->w; x++)127 for (x = 0; x < r->w; x++)
128 count[*(p++)]++;128 count[*(p++)]++;
129 p += r->pict.linesize[0] - r->w;129 p += r->linesize[0] - r->w;
130 }130 }
131 for (i = 0; i < 256; i++) {131 for (i = 0; i < 256; i++) {
132 if (!count[i]) /* avoid useless search */132 if (!count[i]) /* avoid useless search */
@@ -236,14 +236,14 @@ static void copy_rectangle(AVSubtitleRect *dst, AVSubtitleRect *src, int cmap[]) · 103 unmodified lines
236 int x, y;236 int x, y;
237 uint8_t *p, *q;237 uint8_t *p, *q;
238 238
239 p = src->pict.data[0];239 p = src->data[0];
240 q = dst->pict.data[0] + (src->x - dst->x) +240 q = dst->data[0] + (src->x - dst->x) +
241 (src->y - dst->y) * dst->pict.linesize[0];241 (src->y - dst->y) * dst->linesize[0];
242 for (y = 0; y < src->h; y++) {242 for (y = 0; y < src->h; y++) {
243 for (x = 0; x < src->w; x++)243 for (x = 0; x < src->w; x++)
244 *(q++) = cmap[*(p++)];244 *(q++) = cmap[*(p++)];
245 p += src->pict.linesize[0] - src->w;245 p += src->linesize[0] - src->w;
246 q += dst->pict.linesize[0] - src->w;246 q += dst->linesize[0] - src->w;
247 }247 }
248}248}
249 249
@@ -277,6 +277,21 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, · 27 unmodified lines
277 forced = 1;277 forced = 1;
278 break;278 break;
279 }279 }
280
281#if FF_API_AVPICTURE
282FF_DISABLE_DEPRECATION_WARNINGS
283 for (i = 0; i < rects; i++)
284 if (!h->rects[i]->data[0]) {
285 AVSubtitleRect *rect = h->rects[i];
286 int j;
287 for (j = 0; j < 4; j++) {
288 rect->data[j] = rect->pict.data[j];
289 rect->linesize[j] = rect->pict.linesize[j];
290 }
291 }
292FF_ENABLE_DEPRECATION_WARNINGS
293#endif
294
280 vrect = *h->rects[0];295 vrect = *h->rects[0];
281 296
282 if (rects > 1) {297 if (rects > 1) {
@@ -312,17 +327,17 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, · 29 unmodified lines
312 if (rects > 1) {327 if (rects > 1) {
313 if (!(vrect_data = av_calloc(vrect.w, vrect.h)))328 if (!(vrect_data = av_calloc(vrect.w, vrect.h)))
314 return AVERROR(ENOMEM);329 return AVERROR(ENOMEM);
315 vrect.pict.data [0] = vrect_data;330 vrect.data [0] = vrect_data;
316 vrect.pict.linesize[0] = vrect.w;331 vrect.linesize[0] = vrect.w;
317 for (i = 0; i < rects; i++) {332 for (i = 0; i < rects; i++) {
318 build_color_map(avctx, cmap, (uint32_t *)h->rects[i]->pict.data[1],333 build_color_map(avctx, cmap, (uint32_t *)h->rects[i]->data[1],
319 out_palette, out_alpha);334 out_palette, out_alpha);
320 copy_rectangle(&vrect, h->rects[i], cmap);335 copy_rectangle(&vrect, h->rects[i], cmap);
321 }336 }
322 for (i = 0; i < 4; i++)337 for (i = 0; i < 4; i++)
323 cmap[i] = i;338 cmap[i] = i;
324 } else {339 } else {
325 build_color_map(avctx, cmap, (uint32_t *)h->rects[0]->pict.data[1],340 build_color_map(avctx, cmap, (uint32_t *)h->rects[0]->data[1],
326 out_palette, out_alpha);341 out_palette, out_alpha);
327 }342 }
328 343
@@ -342,10 +357,10 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, · 13 unmodified lines
342 ret = AVERROR_BUFFER_TOO_SMALL;357 ret = AVERROR_BUFFER_TOO_SMALL;
343 goto fail;358 goto fail;
344 }359 }
345 dvd_encode_rle(&q, vrect.pict.data[0], vrect.w * 2,360 dvd_encode_rle(&q, vrect.data[0], vrect.w * 2,
346 vrect.w, (vrect.h + 1) >> 1, cmap);361 vrect.w, (vrect.h + 1) >> 1, cmap);
347 offset2 = q - outbuf;362 offset2 = q - outbuf;
348 dvd_encode_rle(&q, vrect.pict.data[0] + vrect.w, vrect.w * 2,363 dvd_encode_rle(&q, vrect.data[0] + vrect.w, vrect.w * 2,
349 vrect.w, vrect.h >> 1, cmap);364 vrect.w, vrect.h >> 1, cmap);
350 365
351 if (dvdc->even_rows_fix && (vrect.h & 1)) {366 if (dvdc->even_rows_fix && (vrect.h & 1)) {
libavcodec/pgssubdec.c+19−8
@@ -166,9 +166,9 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, · 165 unmodified lines
166 166
167 rle_bitmap_end = buf + buf_size;167 rle_bitmap_end = buf + buf_size;
168 168
169 rect->pict.data[0] = av_malloc_array(rect->w, rect->h);169 rect->data[0] = av_malloc_array(rect->w, rect->h);
170 170
171 if (!rect->pict.data[0])171 if (!rect->data[0])
172 return AVERROR(ENOMEM);172 return AVERROR(ENOMEM);
173 173
174 pixel_count = 0;174 pixel_count = 0;
@@ -190,7 +190,7 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, · 15 unmodified lines
190 }190 }
191 191
192 if (run > 0 && pixel_count + run <= rect->w * rect->h) {192 if (run > 0 && pixel_count + run <= rect->w * rect->h) {
193 memset(rect->pict.data[0] + pixel_count, color, run);193 memset(rect->data[0] + pixel_count, color, run);
194 pixel_count += run;194 pixel_count += run;
195 } else if (!run) {195 } else if (!run) {
196 /*196 /*
@@ -523,6 +523,8 @@ static int display_end_segment(AVCodecContext *avctx, void *data, · 326 unmodified lines
523 }523 }
524 for (i = 0; i < ctx->presentation.object_count; i++) {524 for (i = 0; i < ctx->presentation.object_count; i++) {
525 PGSSubObject *object;525 PGSSubObject *object;
526 AVSubtitleRect *rect;
527 int j;
526 528
527 sub->rects[i] = av_mallocz(sizeof(*sub->rects[0]));529 sub->rects[i] = av_mallocz(sizeof(*sub->rects[0]));
528 if (!sub->rects[i]) {530 if (!sub->rects[i]) {
@@ -553,7 +555,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data, · 24 unmodified lines
553 sub->rects[i]->w = object->w;555 sub->rects[i]->w = object->w;
554 sub->rects[i]->h = object->h;556 sub->rects[i]->h = object->h;
555 557
556 sub->rects[i]->pict.linesize[0] = object->w;558 sub->rects[i]->linesize[0] = object->w;
557 559
558 if (object->rle) {560 if (object->rle) {
559 if (object->rle_remaining_len) {561 if (object->rle_remaining_len) {
@@ -578,15 +580,24 @@ static int display_end_segment(AVCodecContext *avctx, void *data, · 18 unmodified lines
578 }580 }
579 /* Allocate memory for colors */581 /* Allocate memory for colors */
580 sub->rects[i]->nb_colors = 256;582 sub->rects[i]->nb_colors = 256;
581 sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);583 sub->rects[i]->data[1] = av_mallocz(AVPALETTE_SIZE);
582 if (!sub->rects[i]->pict.data[1]) {584 if (!sub->rects[i]->data[1]) {
583 avsubtitle_free(sub);585 avsubtitle_free(sub);
584 return AVERROR(ENOMEM);586 return AVERROR(ENOMEM);
585 }587 }
586 588
587 if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)589 if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
588 memcpy(sub->rects[i]->pict.data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));590 memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
589 591
592#if FF_API_AVPICTURE
593FF_DISABLE_DEPRECATION_WARNINGS
594 rect = sub->rects[i];
595 for (j = 0; j < 4; j++) {
596 rect->pict.data[j] = rect->data[j];
597 rect->pict.linesize[j] = rect->linesize[j];
598 }
599FF_ENABLE_DEPRECATION_WARNINGS
600#endif
590 }601 }
591 return 1;602 return 1;
592}603}
libavcodec/utils.c+4−4
@@ -2480,10 +2480,10 @@ void avsubtitle_free(AVSubtitle *sub) · 2479 unmodified lines
2480 int i;2480 int i;
2481 2481
2482 for (i = 0; i < sub->num_rects; i++) {2482 for (i = 0; i < sub->num_rects; i++) {
2483 av_freep(&sub->rects[i]->pict.data[0]);2483 av_freep(&sub->rects[i]->data[0]);
2484 av_freep(&sub->rects[i]->pict.data[1]);2484 av_freep(&sub->rects[i]->data[1]);
2485 av_freep(&sub->rects[i]->pict.data[2]);2485 av_freep(&sub->rects[i]->data[2]);
2486 av_freep(&sub->rects[i]->pict.data[3]);2486 av_freep(&sub->rects[i]->data[3]);
2487 av_freep(&sub->rects[i]->text);2487 av_freep(&sub->rects[i]->text);
2488 av_freep(&sub->rects[i]->ass);2488 av_freep(&sub->rects[i]->ass);
2489 av_freep(&sub->rects[i]);2489 av_freep(&sub->rects[i]);
libavcodec/version.h+4−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
29#include "libavutil/version.h"29#include "libavutil/version.h"
30 30
31#define LIBAVCODEC_VERSION_MAJOR 5731#define LIBAVCODEC_VERSION_MAJOR 57
32#define LIBAVCODEC_VERSION_MINOR 832#define LIBAVCODEC_VERSION_MINOR 9
33#define LIBAVCODEC_VERSION_MICRO 10033#define LIBAVCODEC_VERSION_MICRO 100
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -188,5 +188,8 @@ · 152 unmodified lines
188#ifndef FF_API_CONVERGENCE_DURATION188#ifndef FF_API_CONVERGENCE_DURATION
189#define FF_API_CONVERGENCE_DURATION (LIBAVCODEC_VERSION_MAJOR < 59)189#define FF_API_CONVERGENCE_DURATION (LIBAVCODEC_VERSION_MAJOR < 59)
190#endif190#endif
191#ifndef FF_API_AVPICTURE
192#define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59)
193#endif
191 194
192#endif /* AVCODEC_VERSION_H */195#endif /* AVCODEC_VERSION_H */
libavcodec/xsubdec.c+23−11
@@ -57,6 +57,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 56 unmodified lines
57 int64_t packet_time = 0;57 int64_t packet_time = 0;
58 GetBitContext gb;58 GetBitContext gb;
59 int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');59 int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
60 AVSubtitleRect *rect;
61 int j;
60 62
61 // check that at least header fits63 // check that at least header fits
62 if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {64 if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {
@@ -104,13 +106,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 41 unmodified lines
104 sub->rects[0]->x = x; sub->rects[0]->y = y;106 sub->rects[0]->x = x; sub->rects[0]->y = y;
105 sub->rects[0]->w = w; sub->rects[0]->h = h;107 sub->rects[0]->w = w; sub->rects[0]->h = h;
106 sub->rects[0]->type = SUBTITLE_BITMAP;108 sub->rects[0]->type = SUBTITLE_BITMAP;
107 sub->rects[0]->pict.linesize[0] = w;109 sub->rects[0]->linesize[0] = w;
108 sub->rects[0]->pict.data[0] = av_malloc(w * h);110 sub->rects[0]->data[0] = av_malloc(w * h);
109 sub->rects[0]->nb_colors = 4;111 sub->rects[0]->nb_colors = 4;
110 sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);112 sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE);
111 if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) {113 if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1]) {
112 av_freep(&sub->rects[0]->pict.data[1]);114 av_freep(&sub->rects[0]->data[1]);
113 av_freep(&sub->rects[0]->pict.data[0]);115 av_freep(&sub->rects[0]->data[0]);
114 av_freep(&sub->rects[0]);116 av_freep(&sub->rects[0]);
115 av_freep(&sub->rects);117 av_freep(&sub->rects);
116 return AVERROR(ENOMEM);118 return AVERROR(ENOMEM);
@@ -119,23 +121,33 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 2 unmodified lines
119 121
120 // read palette122 // read palette
121 for (i = 0; i < sub->rects[0]->nb_colors; i++)123 for (i = 0; i < sub->rects[0]->nb_colors; i++)
122 ((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);124 ((uint32_t*)sub->rects[0]->data[1])[i] = bytestream_get_be24(&buf);
123 125
124 if (!has_alpha) {126 if (!has_alpha) {
125 // make all except background (first entry) non-transparent127 // make all except background (first entry) non-transparent
126 for (i = 1; i < sub->rects[0]->nb_colors; i++)128 for (i = 1; i < sub->rects[0]->nb_colors; i++)
127 ((uint32_t *)sub->rects[0]->pict.data[1])[i] |= 0xff000000;129 ((uint32_t *)sub->rects[0]->data[1])[i] |= 0xff000000;
128 } else {130 } else {
129 for (i = 0; i < sub->rects[0]->nb_colors; i++)131 for (i = 0; i < sub->rects[0]->nb_colors; i++)
130 ((uint32_t *)sub->rects[0]->pict.data[1])[i] |= *buf++ << 24;132 ((uint32_t *)sub->rects[0]->data[1])[i] |= *buf++ << 24;
131 }133 }
132 134
135#if FF_API_AVPICTURE
136FF_DISABLE_DEPRECATION_WARNINGS
137 rect = sub->rects[0];
138 for (j = 0; j < 4; j++) {
139 rect->pict.data[j] = rect->data[j];
140 rect->pict.linesize[j] = rect->linesize[j];
141 }
142FF_ENABLE_DEPRECATION_WARNINGS
143#endif
144
133 // process RLE-compressed data145 // process RLE-compressed data
134 init_get_bits(&gb, buf, (buf_end - buf) * 8);146 init_get_bits(&gb, buf, (buf_end - buf) * 8);
135 bitmap = sub->rects[0]->pict.data[0];147 bitmap = sub->rects[0]->data[0];
136 for (y = 0; y < h; y++) {148 for (y = 0; y < h; y++) {
137 // interlaced: do odd lines149 // interlaced: do odd lines
138 if (y == (h + 1) / 2) bitmap = sub->rects[0]->pict.data[0] + w;150 if (y == (h + 1) / 2) bitmap = sub->rects[0]->data[0] + w;
139 for (x = 0; x < w; ) {151 for (x = 0; x < w; ) {
140 int log2 = ff_log2_tab[show_bits(&gb, 8)];152 int log2 = ff_log2_tab[show_bits(&gb, 8)];
141 int run = get_bits(&gb, 14 - 4 * (log2 >> 1));153 int run = get_bits(&gb, 14 - 4 * (log2 >> 1));
libavcodec/xsubenc.c+20−7
@@ -131,8 +131,21 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, · 130 unmodified lines
131 if (h->num_rects != 1)131 if (h->num_rects != 1)
132 av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects);132 av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects);
133 133
134#if FF_API_AVPICTURE
135FF_DISABLE_DEPRECATION_WARNINGS
136 if (!h->rects[0]->data[0]) {
137 AVSubtitleRect *rect = h->rects[0];
138 int j;
139 for (j = 0; j < 4; j++) {
140 rect->data[j] = rect->pict.data[j];
141 rect->linesize[j] = rect->pict.linesize[j];
142 }
143 }
144FF_ENABLE_DEPRECATION_WARNINGS
145#endif
146
134 // TODO: render text-based subtitles into bitmaps147 // TODO: render text-based subtitles into bitmaps
135 if (!h->rects[0]->pict.data[0] || !h->rects[0]->pict.data[1]) {148 if (!h->rects[0]->data[0] || !h->rects[0]->data[1]) {
136 av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n");149 av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n");
137 return -1;150 return -1;
138 }151 }
@@ -142,7 +155,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, · 3 unmodified lines
142 av_log(avctx, AV_LOG_WARNING, "No more than 4 subtitle colors supported (%d found.)\n", h->rects[0]->nb_colors);155 av_log(avctx, AV_LOG_WARNING, "No more than 4 subtitle colors supported (%d found.)\n", h->rects[0]->nb_colors);
143 156
144 // TODO: Palette swapping if color zero is not transparent157 // TODO: Palette swapping if color zero is not transparent
145 if (((uint32_t *)h->rects[0]->pict.data[1])[0] & 0xff000000)158 if (((uint32_t *)h->rects[0]->data[1])[0] & 0xff000000)
146 av_log(avctx, AV_LOG_WARNING, "Color index 0 is not transparent. Transparency will be messed up.\n");159 av_log(avctx, AV_LOG_WARNING, "Color index 0 is not transparent. Transparency will be messed up.\n");
147 160
148 if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) {161 if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) {
@@ -174,19 +187,19 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, · 25 unmodified lines
174 187
175 // Palette188 // Palette
176 for (i=0; i<4; i++)189 for (i=0; i<4; i++)
177 bytestream_put_be24(&hdr, ((uint32_t *)h->rects[0]->pict.data[1])[i]);190 bytestream_put_be24(&hdr, ((uint32_t *)h->rects[0]->data[1])[i]);
178 191
179 // Bitmap192 // Bitmap
180 // RLE buffer. Reserve 2 bytes for possible padding after the last row.193 // RLE buffer. Reserve 2 bytes for possible padding after the last row.
181 init_put_bits(&pb, hdr, bufsize - (hdr - buf) - 2);194 init_put_bits(&pb, hdr, bufsize - (hdr - buf) - 2);
182 if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0],195 if (xsub_encode_rle(&pb, h->rects[0]->data[0],
183 h->rects[0]->pict.linesize[0]*2,196 h->rects[0]->linesize[0] * 2,
184 h->rects[0]->w, (h->rects[0]->h + 1) >> 1))197 h->rects[0]->w, (h->rects[0]->h + 1) >> 1))
185 return -1;198 return -1;
186 bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field199 bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field
187 200
188 if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0] + h->rects[0]->pict.linesize[0],201 if (xsub_encode_rle(&pb, h->rects[0]->data[0] + h->rects[0]->linesize[0],
189 h->rects[0]->pict.linesize[0]*2,202 h->rects[0]->linesize[0] * 2,
190 h->rects[0]->w, h->rects[0]->h >> 1))203 h->rects[0]->w, h->rects[0]->h >> 1))
191 return -1;204 return -1;
192 205

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t