* commit 'a17a7661906ba295d67afd80ac0770422e1b02b3': lavc: Add data and linesize to AVSubtitleRect
Unified · Split
| @@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2015-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 | + | |
| 18 | 22 | 2015-10-22 - xxxxxxx - lavc 57.8.100 / lavc 57.0.0 - qsv.h |
| 19 | 23 | Add an API for allocating opaque surfaces. |
| 20 | 24 | |
| @@ -3618,11 +3618,20 @@ typedef struct AVSubtitleRect { · 3617 unmodified lines | ||
| 3618 | 3618 | int h; ///< height of pict, undefined when pict is not set |
| 3619 | 3619 | 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 | − * can be set for text/ass as well once they are rendered | |
| 3623 | + * @deprecated unused | |
| 3624 | 3624 | */ |
| 3625 | + attribute_deprecated | |
| 3625 | 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 | 3635 | enum AVSubtitleType type; |
| 3627 | 3636 | |
| 3628 | 3637 | char *text; ///< 0 terminated plain UTF-8 text |
| @@ -315,7 +315,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, · 314 unmodified lines | ||
| 315 | 315 | *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */ |
| 316 | 316 | { |
| 317 | 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 | 319 | a = (x >> 24) & 0xff; |
| 320 | 320 | r = (x >> 16) & 0xff; |
| 321 | 321 | g = (x >> 8) & 0xff; |
| @@ -410,10 +410,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, · 88 unmodified lines | ||
| 410 | 410 | q += 2; |
| 411 | 411 | |
| 412 | 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 | 414 | h->rects[object_id]->w, h->rects[object_id]->h >> 1); |
| 415 | 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 | 417 | h->rects[object_id]->w * 2, h->rects[object_id]->w, |
| 418 | 418 | h->rects[object_id]->h >> 1); |
| 419 | 419 | |
| @@ -761,14 +761,14 @@ static int dvbsub_read_8bit_string(AVCodecContext *avctx, · 760 unmodified lines | ||
| 761 | 761 | return pixels_read; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | −static void compute_default_clut(AVPicture *frame, int w, int h) | |
| 764 | +static void compute_default_clut(AVSubtitleRect *rect, int w, int h) | |
| 765 | 765 | { |
| 766 | 766 | uint8_t list[256] = {0}; |
| 767 | 767 | uint8_t list_inv[256]; |
| 768 | 768 | int counttab[256] = {0}; |
| 769 | 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 | 772 | for (y = 0; y<h; y++) { |
| 773 | 773 | for (x = 0; x<w; x++) { |
| 774 | 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 | 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 | 784 | for (i = 0; i<256; i++) { |
| 785 | 785 | int scoretab[256] = {0}; |
| @@ -787,7 +787,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) · 1 unmodified line | ||
| 787 | 787 | int bestv = 0; |
| 788 | 788 | for (y = 0; y<h; y++) { |
| 789 | 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 | 791 | int l_m = list[v]; |
| 792 | 792 | int l_l = x ? L(x-1, y) : 1; |
| 793 | 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 | 813 | count = i - 1; |
| 814 | 814 | for (i--; i>=0; i--) { |
| 815 | 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 | 827 | AVSubtitleRect *rect; |
| 828 | 828 | DVBSubCLUT *clut; |
| 829 | 829 | uint32_t *clut_table; |
| 830 | − int i; | |
| 830 | + int i,j; | |
| 831 | 831 | int offset_x=0, offset_y=0; |
| 832 | 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 | 884 | rect->h = region->height; |
| 885 | 885 | rect->nb_colors = (1 << region->depth); |
| 886 | 886 | rect->type = SUBTITLE_BITMAP; |
| 887 | − rect->pict.linesize[0] = region->width; | |
| 887 | + rect->linesize[0] = region->width; | |
| 888 | 888 | |
| 889 | 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 | 904 | break; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | − rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 908 | − if (!rect->pict.data[1]) { | |
| 907 | + rect->data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 908 | + if (!rect->data[1]) { | |
| 909 | 909 | ret = AVERROR(ENOMEM); |
| 910 | 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); | |
| 915 | − if (!rect->pict.data[0]) { | |
| 914 | + rect->data[0] = av_malloc(region->buf_size); | |
| 915 | + if (!rect->data[0]) { | |
| 916 | 916 | ret = AVERROR(ENOMEM); |
| 917 | 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 | 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 | |
| 926 | +FF_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 | + } | |
| 931 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 932 | +#endif | |
| 924 | 933 | |
| 925 | 934 | i++; |
| 926 | 935 | } |
| @@ -932,8 +941,8 @@ fail: · 5 unmodified lines | ||
| 932 | 941 | for(i=0; i<sub->num_rects; i++) { |
| 933 | 942 | rect = sub->rects[i]; |
| 934 | 943 | if (rect) { |
| 935 | − av_freep(&rect->pict.data[0]); | |
| 936 | − av_freep(&rect->pict.data[1]); | |
| 944 | + av_freep(&rect->data[0]); | |
| 945 | + av_freep(&rect->data[1]); | |
| 937 | 946 | } |
| 938 | 947 | av_freep(&sub->rects[i]); |
| 939 | 948 | } |
| @@ -206,8 +206,8 @@ static void reset_rects(AVSubtitle *sub_header) · 205 unmodified lines | ||
| 206 | 206 | |
| 207 | 207 | if (sub_header->rects) { |
| 208 | 208 | for (i = 0; i < sub_header->num_rects; i++) { |
| 209 | − av_freep(&sub_header->rects[i]->pict.data[0]); | |
| 210 | − av_freep(&sub_header->rects[i]->pict.data[1]); | |
| 209 | + av_freep(&sub_header->rects[i]->data[0]); | |
| 210 | + av_freep(&sub_header->rects[i]->data[1]); | |
| 211 | 211 | av_freep(&sub_header->rects[i]); |
| 212 | 212 | } |
| 213 | 213 | av_freep(&sub_header->rects); |
| @@ -374,7 +374,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, · 160 unmodified lines | ||
| 374 | 374 | if (!sub_header->rects[0]) |
| 375 | 375 | goto fail; |
| 376 | 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 | 378 | if (!bitmap) |
| 379 | 379 | goto fail; |
| 380 | 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 | 383 | if (decode_rle(bitmap + w, w * 2, w, h / 2, |
| 384 | 384 | buf, offset2, buf_size, is_8bit) < 0) |
| 385 | 385 | goto fail; |
| 386 | − sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 387 | − if (!sub_header->rects[0]->pict.data[1]) | |
| 386 | + sub_header->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 387 | + if (!sub_header->rects[0]->data[1]) | |
| 388 | 388 | goto fail; |
| 389 | 389 | if (is_8bit) { |
| 390 | 390 | if (!yuv_palette) |
| 391 | 391 | goto fail; |
| 392 | 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 | 396 | } else { |
| 395 | 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 | 399 | 0xffff00); |
| 398 | 400 | } |
| 399 | 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 | 403 | sub_header->rects[0]->w = w; |
| 402 | 404 | sub_header->rects[0]->h = h; |
| 403 | 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 | 407 | sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0; |
| 408 | + | |
| 409 | +#if FF_API_AVPICTURE | |
| 410 | +FF_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 | + } | |
| 415 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 416 | +#endif | |
| 406 | 417 | } |
| 407 | 418 | } |
| 408 | 419 | if (next_cmd_pos < cmd_pos) { |
| @@ -443,29 +454,29 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) · 34 unmodified lines | ||
| 443 | 454 | return 0; |
| 444 | 455 | |
| 445 | 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 | 458 | transp_color[i] = 1; |
| 448 | 459 | } |
| 449 | 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 | 462 | 1, s->rects[0]->w, transp_color)) |
| 452 | 463 | y1++; |
| 453 | 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 | 466 | s->rects[0]->w = s->rects[0]->h = 0; |
| 456 | 467 | return 0; |
| 457 | 468 | } |
| 458 | 469 | |
| 459 | 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 | 472 | s->rects[0]->w, transp_color)) |
| 462 | 473 | y2--; |
| 463 | 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 | 476 | s->rects[0]->h, transp_color)) |
| 466 | 477 | x1++; |
| 467 | 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 | 480 | transp_color)) |
| 470 | 481 | x2--; |
| 471 | 482 | w = x2 - x1 + 1; |
| @@ -474,15 +485,25 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) · 2 unmodified lines | ||
| 474 | 485 | if (!bitmap) |
| 475 | 486 | return 1; |
| 476 | 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]); | |
| 480 | − s->rects[0]->pict.data[0] = bitmap; | |
| 481 | − s->rects[0]->pict.linesize[0] = w; | |
| 490 | + av_freep(&s->rects[0]->data[0]); | |
| 491 | + s->rects[0]->data[0] = bitmap; | |
| 492 | + s->rects[0]->linesize[0] = w; | |
| 482 | 493 | s->rects[0]->w = w; |
| 483 | 494 | s->rects[0]->h = h; |
| 484 | 495 | s->rects[0]->x += x1; |
| 485 | 496 | s->rects[0]->y += y1; |
| 497 | + | |
| 498 | +#if FF_API_AVPICTURE | |
| 499 | +FF_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 | + } | |
| 504 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 505 | +#endif | |
| 506 | + | |
| 486 | 507 | return 1; |
| 487 | 508 | } |
| 488 | 509 | |
| @@ -583,8 +604,8 @@ static int dvdsub_decode(AVCodecContext *avctx, · 94 unmodified lines | ||
| 583 | 604 | ff_dlog(NULL, "start=%d ms end =%d ms\n", |
| 584 | 605 | sub->start_display_time, |
| 585 | 606 | sub->end_display_time); |
| 586 | − ppm_save(ppm_name, sub->rects[0]->pict.data[0], | |
| 587 | − sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]); | |
| 607 | + ppm_save(ppm_name, sub->rects[0]->data[0], | |
| 608 | + sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->data[1]); | |
| 588 | 609 | } |
| 589 | 610 | #endif |
| 590 | 611 | |
| @@ -118,15 +118,15 @@ static void count_colors(AVCodecContext *avctx, unsigned hits[33], · 117 unmodified lines | ||
| 118 | 118 | { |
| 119 | 119 | DVDSubtitleContext *dvdc = avctx->priv_data; |
| 120 | 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 | 122 | uint32_t color; |
| 123 | 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 | 126 | for (y = 0; y < r->h; y++) { |
| 127 | 127 | for (x = 0; x < r->w; x++) |
| 128 | 128 | count[*(p++)]++; |
| 129 | − p += r->pict.linesize[0] - r->w; | |
| 129 | + p += r->linesize[0] - r->w; | |
| 130 | 130 | } |
| 131 | 131 | for (i = 0; i < 256; i++) { |
| 132 | 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 | 236 | int x, y; |
| 237 | 237 | uint8_t *p, *q; |
| 238 | 238 | |
| 239 | − p = src->pict.data[0]; | |
| 240 | − q = dst->pict.data[0] + (src->x - dst->x) + | |
| 241 | − (src->y - dst->y) * dst->pict.linesize[0]; | |
| 239 | + p = src->data[0]; | |
| 240 | + q = dst->data[0] + (src->x - dst->x) + | |
| 241 | + (src->y - dst->y) * dst->linesize[0]; | |
| 242 | 242 | for (y = 0; y < src->h; y++) { |
| 243 | 243 | for (x = 0; x < src->w; x++) |
| 244 | 244 | *(q++) = cmap[*(p++)]; |
| 245 | − p += src->pict.linesize[0] - src->w; | |
| 246 | − q += dst->pict.linesize[0] - src->w; | |
| 245 | + p += src->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 | 277 | forced = 1; |
| 278 | 278 | break; |
| 279 | 279 | } |
| 280 | + | |
| 281 | +#if FF_API_AVPICTURE | |
| 282 | +FF_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 | + } | |
| 292 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 293 | +#endif | |
| 294 | + | |
| 280 | 295 | vrect = *h->rects[0]; |
| 281 | 296 | |
| 282 | 297 | if (rects > 1) { |
| @@ -312,17 +327,17 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, · 29 unmodified lines | ||
| 312 | 327 | if (rects > 1) { |
| 313 | 328 | if (!(vrect_data = av_calloc(vrect.w, vrect.h))) |
| 314 | 329 | return AVERROR(ENOMEM); |
| 315 | − vrect.pict.data [0] = vrect_data; | |
| 316 | − vrect.pict.linesize[0] = vrect.w; | |
| 330 | + vrect.data [0] = vrect_data; | |
| 331 | + vrect.linesize[0] = vrect.w; | |
| 317 | 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 | 334 | out_palette, out_alpha); |
| 320 | 335 | copy_rectangle(&vrect, h->rects[i], cmap); |
| 321 | 336 | } |
| 322 | 337 | for (i = 0; i < 4; i++) |
| 323 | 338 | cmap[i] = i; |
| 324 | 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 | 341 | out_palette, out_alpha); |
| 327 | 342 | } |
| 328 | 343 | |
| @@ -342,10 +357,10 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, · 13 unmodified lines | ||
| 342 | 357 | ret = AVERROR_BUFFER_TOO_SMALL; |
| 343 | 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 | 361 | vrect.w, (vrect.h + 1) >> 1, cmap); |
| 347 | 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 | 364 | vrect.w, vrect.h >> 1, cmap); |
| 350 | 365 | |
| 351 | 366 | if (dvdc->even_rows_fix && (vrect.h & 1)) { |
| @@ -166,9 +166,9 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, · 165 unmodified lines | ||
| 166 | 166 | |
| 167 | 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 | 172 | return AVERROR(ENOMEM); |
| 173 | 173 | |
| 174 | 174 | pixel_count = 0; |
| @@ -190,7 +190,7 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, · 15 unmodified lines | ||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 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 | 194 | pixel_count += run; |
| 195 | 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 | 524 | for (i = 0; i < ctx->presentation.object_count; i++) { |
| 525 | 525 | PGSSubObject *object; |
| 526 | + AVSubtitleRect *rect; | |
| 527 | + int j; | |
| 526 | 528 | |
| 527 | 529 | sub->rects[i] = av_mallocz(sizeof(*sub->rects[0])); |
| 528 | 530 | if (!sub->rects[i]) { |
| @@ -553,7 +555,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data, · 24 unmodified lines | ||
| 553 | 555 | sub->rects[i]->w = object->w; |
| 554 | 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 | 560 | if (object->rle) { |
| 559 | 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 | 581 | /* Allocate memory for colors */ |
| 580 | 582 | sub->rects[i]->nb_colors = 256; |
| 581 | − sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 582 | − if (!sub->rects[i]->pict.data[1]) { | |
| 583 | + sub->rects[i]->data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 584 | + if (!sub->rects[i]->data[1]) { | |
| 583 | 585 | avsubtitle_free(sub); |
| 584 | 586 | return AVERROR(ENOMEM); |
| 585 | 587 | } |
| 586 | 588 | |
| 587 | 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)); | |
| 589 | − | |
| 590 | + memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t)); | |
| 591 | + | |
| 592 | +#if FF_API_AVPICTURE | |
| 593 | +FF_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 | + } | |
| 599 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 600 | +#endif | |
| 590 | 601 | } |
| 591 | 602 | return 1; |
| 592 | 603 | } |
| @@ -2480,10 +2480,10 @@ void avsubtitle_free(AVSubtitle *sub) · 2479 unmodified lines | ||
| 2480 | 2480 | int i; |
| 2481 | 2481 | |
| 2482 | 2482 | for (i = 0; i < sub->num_rects; i++) { |
| 2483 | − av_freep(&sub->rects[i]->pict.data[0]); | |
| 2484 | − av_freep(&sub->rects[i]->pict.data[1]); | |
| 2485 | − av_freep(&sub->rects[i]->pict.data[2]); | |
| 2486 | − av_freep(&sub->rects[i]->pict.data[3]); | |
| 2483 | + av_freep(&sub->rects[i]->data[0]); | |
| 2484 | + av_freep(&sub->rects[i]->data[1]); | |
| 2485 | + av_freep(&sub->rects[i]->data[2]); | |
| 2486 | + av_freep(&sub->rects[i]->data[3]); | |
| 2487 | 2487 | av_freep(&sub->rects[i]->text); |
| 2488 | 2488 | av_freep(&sub->rects[i]->ass); |
| 2489 | 2489 | av_freep(&sub->rects[i]); |
| @@ -29,7 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | #include "libavutil/version.h" |
| 30 | 30 | |
| 31 | 31 | #define LIBAVCODEC_VERSION_MAJOR 57 |
| 32 | −#define LIBAVCODEC_VERSION_MINOR 8 | |
| 32 | +#define LIBAVCODEC_VERSION_MINOR 9 | |
| 33 | 33 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 34 | 34 | |
| 35 | 35 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -188,5 +188,8 @@ · 152 unmodified lines | ||
| 188 | 188 | #ifndef FF_API_CONVERGENCE_DURATION |
| 189 | 189 | #define FF_API_CONVERGENCE_DURATION (LIBAVCODEC_VERSION_MAJOR < 59) |
| 190 | 190 | #endif |
| 191 | +#ifndef FF_API_AVPICTURE | |
| 192 | +#define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59) | |
| 193 | +#endif | |
| 191 | 194 | |
| 192 | 195 | #endif /* AVCODEC_VERSION_H */ |
| @@ -57,6 +57,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 56 unmodified lines | ||
| 57 | 57 | int64_t packet_time = 0; |
| 58 | 58 | GetBitContext gb; |
| 59 | 59 | int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); |
| 60 | + AVSubtitleRect *rect; | |
| 61 | + int j; | |
| 60 | 62 | |
| 61 | 63 | // check that at least header fits |
| 62 | 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 | 106 | sub->rects[0]->x = x; sub->rects[0]->y = y; |
| 105 | 107 | sub->rects[0]->w = w; sub->rects[0]->h = h; |
| 106 | 108 | sub->rects[0]->type = SUBTITLE_BITMAP; |
| 107 | − sub->rects[0]->pict.linesize[0] = w; | |
| 108 | − sub->rects[0]->pict.data[0] = av_malloc(w * h); | |
| 109 | + sub->rects[0]->linesize[0] = w; | |
| 110 | + sub->rects[0]->data[0] = av_malloc(w * h); | |
| 109 | 111 | sub->rects[0]->nb_colors = 4; |
| 110 | − sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 111 | − if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) { | |
| 112 | − av_freep(&sub->rects[0]->pict.data[1]); | |
| 113 | − av_freep(&sub->rects[0]->pict.data[0]); | |
| 112 | + sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE); | |
| 113 | + if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1]) { | |
| 114 | + av_freep(&sub->rects[0]->data[1]); | |
| 115 | + av_freep(&sub->rects[0]->data[0]); | |
| 114 | 116 | av_freep(&sub->rects[0]); |
| 115 | 117 | av_freep(&sub->rects); |
| 116 | 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 | 122 | // read palette |
| 121 | 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 | 126 | if (!has_alpha) { |
| 125 | 127 | // make all except background (first entry) non-transparent |
| 126 | 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 | 130 | } else { |
| 129 | 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 | |
| 136 | +FF_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 | + } | |
| 142 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 143 | +#endif | |
| 144 | + | |
| 133 | 145 | // process RLE-compressed data |
| 134 | 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 | 148 | for (y = 0; y < h; y++) { |
| 137 | 149 | // 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 | 151 | for (x = 0; x < w; ) { |
| 140 | 152 | int log2 = ff_log2_tab[show_bits(&gb, 8)]; |
| 141 | 153 | int run = get_bits(&gb, 14 - 4 * (log2 >> 1)); |
| @@ -131,8 +131,21 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, · 130 unmodified lines | ||
| 131 | 131 | if (h->num_rects != 1) |
| 132 | 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 | |
| 135 | +FF_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 | + } | |
| 144 | +FF_ENABLE_DEPRECATION_WARNINGS | |
| 145 | +#endif | |
| 146 | + | |
| 134 | 147 | // 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 | 149 | av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n"); |
| 137 | 150 | return -1; |
| 138 | 151 | } |
| @@ -142,7 +155,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, · 3 unmodified lines | ||
| 142 | 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 | 157 | // 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 | 159 | av_log(avctx, AV_LOG_WARNING, "Color index 0 is not transparent. Transparency will be messed up.\n"); |
| 147 | 160 | |
| 148 | 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 | 188 | // Palette |
| 176 | 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 | 192 | // Bitmap |
| 180 | 193 | // RLE buffer. Reserve 2 bytes for possible padding after the last row. |
| 181 | 194 | init_put_bits(&pb, hdr, bufsize - (hdr - buf) - 2); |
| 182 | − if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0], | |
| 183 | − h->rects[0]->pict.linesize[0]*2, | |
| 195 | + if (xsub_encode_rle(&pb, h->rects[0]->data[0], | |
| 196 | + h->rects[0]->linesize[0] * 2, | |
| 184 | 197 | h->rects[0]->w, (h->rects[0]->h + 1) >> 1)) |
| 185 | 198 | return -1; |
| 186 | 199 | 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], | |
| 189 | − h->rects[0]->pict.linesize[0]*2, | |
| 201 | + if (xsub_encode_rle(&pb, h->rects[0]->data[0] + h->rects[0]->linesize[0], | |
| 202 | + h->rects[0]->linesize[0] * 2, | |
| 190 | 203 | h->rects[0]->w, h->rects[0]->h >> 1)) |
| 191 | 204 | return -1; |
| 192 | 205 | |