* commit 'a17a7661906ba295d67afd80ac0770422e1b02b3': lavc: Add data and linesize to AVSubtitleRect Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>tags/n3.0
| @@ -15,6 +15,10 @@ libavutil: 2015-08-28 | |||
| API changes, most recent first: | |||
| 2015-10-22 - xxxxxxx - lavc 57.9.100 / lavc 57.5.0 - avcodec.h | |||
| Add data and linesize array to AVSubtitleRect, to be used instead of | |||
| the ones from the embedded AVPicture. | |||
| 2015-10-22 - xxxxxxx - lavc 57.8.100 / lavc 57.0.0 - qsv.h | |||
| Add an API for allocating opaque surfaces. | |||
| @@ -3618,11 +3618,20 @@ typedef struct AVSubtitleRect { | |||
| int h; ///< height of pict, undefined when pict is not set | |||
| int nb_colors; ///< number of colors in pict, undefined when pict is not set | |||
| #if FF_API_AVPICTURE | |||
| /** | |||
| * data+linesize for the bitmap of this subtitle. | |||
| * can be set for text/ass as well once they are rendered | |||
| * @deprecated unused | |||
| */ | |||
| attribute_deprecated | |||
| AVPicture pict; | |||
| #endif | |||
| /** | |||
| * data+linesize for the bitmap of this subtitle. | |||
| * Can be set for text/ass as well once they are rendered. | |||
| */ | |||
| uint8_t *data[4]; | |||
| int linesize[4]; | |||
| enum AVSubtitleType type; | |||
| char *text; ///< 0 terminated plain UTF-8 text | |||
| @@ -315,7 +315,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, | |||
| *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */ | |||
| { | |||
| int a, r, g, b; | |||
| uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i]; | |||
| uint32_t x= ((uint32_t*)h->rects[clut_id]->data[1])[i]; | |||
| a = (x >> 24) & 0xff; | |||
| r = (x >> 16) & 0xff; | |||
| g = (x >> 8) & 0xff; | |||
| @@ -410,10 +410,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, | |||
| q += 2; | |||
| top_ptr = q; | |||
| dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2, | |||
| dvb_encode_rle(&q, h->rects[object_id]->data[0], h->rects[object_id]->w * 2, | |||
| h->rects[object_id]->w, h->rects[object_id]->h >> 1); | |||
| bottom_ptr = q; | |||
| dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w, | |||
| dvb_encode_rle(&q, h->rects[object_id]->data[0] + h->rects[object_id]->w, | |||
| h->rects[object_id]->w * 2, h->rects[object_id]->w, | |||
| h->rects[object_id]->h >> 1); | |||
| @@ -761,14 +761,14 @@ static int dvbsub_read_8bit_string(AVCodecContext *avctx, | |||
| return pixels_read; | |||
| } | |||
| static void compute_default_clut(AVPicture *frame, int w, int h) | |||
| static void compute_default_clut(AVSubtitleRect *rect, int w, int h) | |||
| { | |||
| uint8_t list[256] = {0}; | |||
| uint8_t list_inv[256]; | |||
| int counttab[256] = {0}; | |||
| int count, i, x, y; | |||
| #define V(x,y) frame->data[0][(x) + (y)*frame->linesize[0]] | |||
| #define V(x,y) rect->data[0][(x) + (y)*rect->linesize[0]] | |||
| for (y = 0; y<h; y++) { | |||
| for (x = 0; x<w; x++) { | |||
| int v = V(x,y) + 1; | |||
| @@ -779,7 +779,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) | |||
| counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb)); | |||
| } | |||
| } | |||
| #define L(x,y) list[ frame->data[0][(x) + (y)*frame->linesize[0]] ] | |||
| #define L(x,y) list[ rect->data[0][(x) + (y)*rect->linesize[0]] ] | |||
| for (i = 0; i<256; i++) { | |||
| int scoretab[256] = {0}; | |||
| @@ -787,7 +787,7 @@ static void compute_default_clut(AVPicture *frame, int w, int h) | |||
| int bestv = 0; | |||
| for (y = 0; y<h; y++) { | |||
| for (x = 0; x<w; x++) { | |||
| int v = frame->data[0][x + y*frame->linesize[0]]; | |||
| int v = rect->data[0][x + y*rect->linesize[0]]; | |||
| int l_m = list[v]; | |||
| int l_l = x ? L(x-1, y) : 1; | |||
| 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) | |||
| count = i - 1; | |||
| for (i--; i>=0; i--) { | |||
| int v = i*255/count; | |||
| AV_WN32(frame->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v)); | |||
| AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v)); | |||
| } | |||
| } | |||
| @@ -827,7 +827,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou | |||
| AVSubtitleRect *rect; | |||
| DVBSubCLUT *clut; | |||
| uint32_t *clut_table; | |||
| int i; | |||
| int i,j; | |||
| int offset_x=0, offset_y=0; | |||
| int ret = 0; | |||
| @@ -884,7 +884,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou | |||
| rect->h = region->height; | |||
| rect->nb_colors = (1 << region->depth); | |||
| rect->type = SUBTITLE_BITMAP; | |||
| rect->pict.linesize[0] = region->width; | |||
| rect->linesize[0] = region->width; | |||
| clut = get_clut(ctx, region->clut); | |||
| @@ -904,23 +904,32 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou | |||
| break; | |||
| } | |||
| rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!rect->pict.data[1]) { | |||
| rect->data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!rect->data[1]) { | |||
| ret = AVERROR(ENOMEM); | |||
| goto fail; | |||
| } | |||
| memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); | |||
| memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); | |||
| rect->pict.data[0] = av_malloc(region->buf_size); | |||
| if (!rect->pict.data[0]) { | |||
| rect->data[0] = av_malloc(region->buf_size); | |||
| if (!rect->data[0]) { | |||
| ret = AVERROR(ENOMEM); | |||
| goto fail; | |||
| } | |||
| memcpy(rect->pict.data[0], region->pbuf, region->buf_size); | |||
| memcpy(rect->data[0], region->pbuf, region->buf_size); | |||
| if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1) | |||
| compute_default_clut(&rect->pict, rect->w, rect->h); | |||
| compute_default_clut(rect, rect->w, rect->h); | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| for (j = 0; j < 4; j++) { | |||
| rect->pict.data[j] = rect->data[j]; | |||
| rect->pict.linesize[j] = rect->linesize[j]; | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| i++; | |||
| } | |||
| @@ -932,8 +941,8 @@ fail: | |||
| for(i=0; i<sub->num_rects; i++) { | |||
| rect = sub->rects[i]; | |||
| if (rect) { | |||
| av_freep(&rect->pict.data[0]); | |||
| av_freep(&rect->pict.data[1]); | |||
| av_freep(&rect->data[0]); | |||
| av_freep(&rect->data[1]); | |||
| } | |||
| av_freep(&sub->rects[i]); | |||
| } | |||
| @@ -206,8 +206,8 @@ static void reset_rects(AVSubtitle *sub_header) | |||
| if (sub_header->rects) { | |||
| for (i = 0; i < sub_header->num_rects; i++) { | |||
| av_freep(&sub_header->rects[i]->pict.data[0]); | |||
| av_freep(&sub_header->rects[i]->pict.data[1]); | |||
| av_freep(&sub_header->rects[i]->data[0]); | |||
| av_freep(&sub_header->rects[i]->data[1]); | |||
| av_freep(&sub_header->rects[i]); | |||
| } | |||
| av_freep(&sub_header->rects); | |||
| @@ -374,7 +374,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, | |||
| if (!sub_header->rects[0]) | |||
| goto fail; | |||
| sub_header->num_rects = 1; | |||
| bitmap = sub_header->rects[0]->pict.data[0] = av_malloc(w * h); | |||
| bitmap = sub_header->rects[0]->data[0] = av_malloc(w * h); | |||
| if (!bitmap) | |||
| goto fail; | |||
| if (decode_rle(bitmap, w * 2, w, (h + 1) / 2, | |||
| @@ -383,17 +383,19 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, | |||
| if (decode_rle(bitmap + w, w * 2, w, h / 2, | |||
| buf, offset2, buf_size, is_8bit) < 0) | |||
| goto fail; | |||
| sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub_header->rects[0]->pict.data[1]) | |||
| sub_header->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub_header->rects[0]->data[1]) | |||
| goto fail; | |||
| if (is_8bit) { | |||
| if (!yuv_palette) | |||
| goto fail; | |||
| sub_header->rects[0]->nb_colors = 256; | |||
| yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256); | |||
| yuv_a_to_rgba(yuv_palette, alpha, | |||
| (uint32_t *)sub_header->rects[0]->data[1], | |||
| 256); | |||
| } else { | |||
| sub_header->rects[0]->nb_colors = 4; | |||
| guess_palette(ctx, (uint32_t*)sub_header->rects[0]->pict.data[1], | |||
| guess_palette(ctx, (uint32_t*)sub_header->rects[0]->data[1], | |||
| 0xffff00); | |||
| } | |||
| sub_header->rects[0]->x = x1; | |||
| @@ -401,8 +403,17 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, | |||
| sub_header->rects[0]->w = w; | |||
| sub_header->rects[0]->h = h; | |||
| sub_header->rects[0]->type = SUBTITLE_BITMAP; | |||
| sub_header->rects[0]->pict.linesize[0] = w; | |||
| sub_header->rects[0]->linesize[0] = w; | |||
| sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0; | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| for (i = 0; i < 4; i++) { | |||
| sub_header->rects[0]->pict.data[i] = sub_header->rects[0]->data[i]; | |||
| sub_header->rects[0]->pict.linesize[i] = sub_header->rects[0]->linesize[i]; | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| } | |||
| } | |||
| if (next_cmd_pos < cmd_pos) { | |||
| @@ -443,29 +454,29 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) | |||
| return 0; | |||
| for(i = 0; i < s->rects[0]->nb_colors; i++) { | |||
| if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0) | |||
| if ((((uint32_t *)s->rects[0]->data[1])[i] >> 24) == 0) | |||
| transp_color[i] = 1; | |||
| } | |||
| y1 = 0; | |||
| while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0], | |||
| while (y1 < s->rects[0]->h && is_transp(s->rects[0]->data[0] + y1 * s->rects[0]->linesize[0], | |||
| 1, s->rects[0]->w, transp_color)) | |||
| y1++; | |||
| if (y1 == s->rects[0]->h) { | |||
| av_freep(&s->rects[0]->pict.data[0]); | |||
| av_freep(&s->rects[0]->data[0]); | |||
| s->rects[0]->w = s->rects[0]->h = 0; | |||
| return 0; | |||
| } | |||
| y2 = s->rects[0]->h - 1; | |||
| while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1, | |||
| while (y2 > 0 && is_transp(s->rects[0]->data[0] + y2 * s->rects[0]->linesize[0], 1, | |||
| s->rects[0]->w, transp_color)) | |||
| y2--; | |||
| x1 = 0; | |||
| while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0], | |||
| while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->data[0] + x1, s->rects[0]->linesize[0], | |||
| s->rects[0]->h, transp_color)) | |||
| x1++; | |||
| x2 = s->rects[0]->w - 1; | |||
| while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h, | |||
| while (x2 > 0 && is_transp(s->rects[0]->data[0] + x2, s->rects[0]->linesize[0], s->rects[0]->h, | |||
| transp_color)) | |||
| x2--; | |||
| w = x2 - x1 + 1; | |||
| @@ -474,15 +485,25 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) | |||
| if (!bitmap) | |||
| return 1; | |||
| for(y = 0; y < h; y++) { | |||
| memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w); | |||
| memcpy(bitmap + w * y, s->rects[0]->data[0] + x1 + (y1 + y) * s->rects[0]->linesize[0], w); | |||
| } | |||
| av_freep(&s->rects[0]->pict.data[0]); | |||
| s->rects[0]->pict.data[0] = bitmap; | |||
| s->rects[0]->pict.linesize[0] = w; | |||
| av_freep(&s->rects[0]->data[0]); | |||
| s->rects[0]->data[0] = bitmap; | |||
| s->rects[0]->linesize[0] = w; | |||
| s->rects[0]->w = w; | |||
| s->rects[0]->h = h; | |||
| s->rects[0]->x += x1; | |||
| s->rects[0]->y += y1; | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| for (i = 0; i < 4; i++) { | |||
| s->rects[0]->pict.data[i] = s->rects[0]->data[i]; | |||
| s->rects[0]->pict.linesize[i] = s->rects[0]->linesize[i]; | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| return 1; | |||
| } | |||
| @@ -583,8 +604,8 @@ static int dvdsub_decode(AVCodecContext *avctx, | |||
| ff_dlog(NULL, "start=%d ms end =%d ms\n", | |||
| sub->start_display_time, | |||
| sub->end_display_time); | |||
| ppm_save(ppm_name, sub->rects[0]->pict.data[0], | |||
| sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]); | |||
| ppm_save(ppm_name, sub->rects[0]->data[0], | |||
| sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->data[1]); | |||
| } | |||
| #endif | |||
| @@ -118,15 +118,15 @@ static void count_colors(AVCodecContext *avctx, unsigned hits[33], | |||
| { | |||
| DVDSubtitleContext *dvdc = avctx->priv_data; | |||
| unsigned count[256] = { 0 }; | |||
| uint32_t *palette = (uint32_t *)r->pict.data[1]; | |||
| uint32_t *palette = (uint32_t *)r->data[1]; | |||
| uint32_t color; | |||
| int x, y, i, j, match, d, best_d, av_uninit(best_j); | |||
| uint8_t *p = r->pict.data[0]; | |||
| uint8_t *p = r->data[0]; | |||
| for (y = 0; y < r->h; y++) { | |||
| for (x = 0; x < r->w; x++) | |||
| count[*(p++)]++; | |||
| p += r->pict.linesize[0] - r->w; | |||
| p += r->linesize[0] - r->w; | |||
| } | |||
| for (i = 0; i < 256; i++) { | |||
| if (!count[i]) /* avoid useless search */ | |||
| @@ -236,14 +236,14 @@ static void copy_rectangle(AVSubtitleRect *dst, AVSubtitleRect *src, int cmap[]) | |||
| int x, y; | |||
| uint8_t *p, *q; | |||
| p = src->pict.data[0]; | |||
| q = dst->pict.data[0] + (src->x - dst->x) + | |||
| (src->y - dst->y) * dst->pict.linesize[0]; | |||
| p = src->data[0]; | |||
| q = dst->data[0] + (src->x - dst->x) + | |||
| (src->y - dst->y) * dst->linesize[0]; | |||
| for (y = 0; y < src->h; y++) { | |||
| for (x = 0; x < src->w; x++) | |||
| *(q++) = cmap[*(p++)]; | |||
| p += src->pict.linesize[0] - src->w; | |||
| q += dst->pict.linesize[0] - src->w; | |||
| p += src->linesize[0] - src->w; | |||
| q += dst->linesize[0] - src->w; | |||
| } | |||
| } | |||
| @@ -277,6 +277,21 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, | |||
| forced = 1; | |||
| break; | |||
| } | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| for (i = 0; i < rects; i++) | |||
| if (!h->rects[i]->data[0]) { | |||
| AVSubtitleRect *rect = h->rects[i]; | |||
| int j; | |||
| for (j = 0; j < 4; j++) { | |||
| rect->data[j] = rect->pict.data[j]; | |||
| rect->linesize[j] = rect->pict.linesize[j]; | |||
| } | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| vrect = *h->rects[0]; | |||
| if (rects > 1) { | |||
| @@ -312,17 +327,17 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, | |||
| if (rects > 1) { | |||
| if (!(vrect_data = av_calloc(vrect.w, vrect.h))) | |||
| return AVERROR(ENOMEM); | |||
| vrect.pict.data [0] = vrect_data; | |||
| vrect.pict.linesize[0] = vrect.w; | |||
| vrect.data [0] = vrect_data; | |||
| vrect.linesize[0] = vrect.w; | |||
| for (i = 0; i < rects; i++) { | |||
| build_color_map(avctx, cmap, (uint32_t *)h->rects[i]->pict.data[1], | |||
| build_color_map(avctx, cmap, (uint32_t *)h->rects[i]->data[1], | |||
| out_palette, out_alpha); | |||
| copy_rectangle(&vrect, h->rects[i], cmap); | |||
| } | |||
| for (i = 0; i < 4; i++) | |||
| cmap[i] = i; | |||
| } else { | |||
| build_color_map(avctx, cmap, (uint32_t *)h->rects[0]->pict.data[1], | |||
| build_color_map(avctx, cmap, (uint32_t *)h->rects[0]->data[1], | |||
| out_palette, out_alpha); | |||
| } | |||
| @@ -342,10 +357,10 @@ static int encode_dvd_subtitles(AVCodecContext *avctx, | |||
| ret = AVERROR_BUFFER_TOO_SMALL; | |||
| goto fail; | |||
| } | |||
| dvd_encode_rle(&q, vrect.pict.data[0], vrect.w * 2, | |||
| dvd_encode_rle(&q, vrect.data[0], vrect.w * 2, | |||
| vrect.w, (vrect.h + 1) >> 1, cmap); | |||
| offset2 = q - outbuf; | |||
| dvd_encode_rle(&q, vrect.pict.data[0] + vrect.w, vrect.w * 2, | |||
| dvd_encode_rle(&q, vrect.data[0] + vrect.w, vrect.w * 2, | |||
| vrect.w, vrect.h >> 1, cmap); | |||
| if (dvdc->even_rows_fix && (vrect.h & 1)) { | |||
| @@ -166,9 +166,9 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, | |||
| rle_bitmap_end = buf + buf_size; | |||
| rect->pict.data[0] = av_malloc_array(rect->w, rect->h); | |||
| rect->data[0] = av_malloc_array(rect->w, rect->h); | |||
| if (!rect->pict.data[0]) | |||
| if (!rect->data[0]) | |||
| return AVERROR(ENOMEM); | |||
| pixel_count = 0; | |||
| @@ -190,7 +190,7 @@ static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, | |||
| } | |||
| if (run > 0 && pixel_count + run <= rect->w * rect->h) { | |||
| memset(rect->pict.data[0] + pixel_count, color, run); | |||
| memset(rect->data[0] + pixel_count, color, run); | |||
| pixel_count += run; | |||
| } else if (!run) { | |||
| /* | |||
| @@ -523,6 +523,8 @@ static int display_end_segment(AVCodecContext *avctx, void *data, | |||
| } | |||
| for (i = 0; i < ctx->presentation.object_count; i++) { | |||
| PGSSubObject *object; | |||
| AVSubtitleRect *rect; | |||
| int j; | |||
| sub->rects[i] = av_mallocz(sizeof(*sub->rects[0])); | |||
| if (!sub->rects[i]) { | |||
| @@ -553,7 +555,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data, | |||
| sub->rects[i]->w = object->w; | |||
| sub->rects[i]->h = object->h; | |||
| sub->rects[i]->pict.linesize[0] = object->w; | |||
| sub->rects[i]->linesize[0] = object->w; | |||
| if (object->rle) { | |||
| if (object->rle_remaining_len) { | |||
| @@ -578,15 +580,24 @@ static int display_end_segment(AVCodecContext *avctx, void *data, | |||
| } | |||
| /* Allocate memory for colors */ | |||
| sub->rects[i]->nb_colors = 256; | |||
| sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub->rects[i]->pict.data[1]) { | |||
| sub->rects[i]->data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub->rects[i]->data[1]) { | |||
| avsubtitle_free(sub); | |||
| return AVERROR(ENOMEM); | |||
| } | |||
| if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40) | |||
| memcpy(sub->rects[i]->pict.data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t)); | |||
| memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t)); | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| rect = sub->rects[i]; | |||
| for (j = 0; j < 4; j++) { | |||
| rect->pict.data[j] = rect->data[j]; | |||
| rect->pict.linesize[j] = rect->linesize[j]; | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| } | |||
| return 1; | |||
| } | |||
| @@ -2480,10 +2480,10 @@ void avsubtitle_free(AVSubtitle *sub) | |||
| int i; | |||
| for (i = 0; i < sub->num_rects; i++) { | |||
| av_freep(&sub->rects[i]->pict.data[0]); | |||
| av_freep(&sub->rects[i]->pict.data[1]); | |||
| av_freep(&sub->rects[i]->pict.data[2]); | |||
| av_freep(&sub->rects[i]->pict.data[3]); | |||
| av_freep(&sub->rects[i]->data[0]); | |||
| av_freep(&sub->rects[i]->data[1]); | |||
| av_freep(&sub->rects[i]->data[2]); | |||
| av_freep(&sub->rects[i]->data[3]); | |||
| av_freep(&sub->rects[i]->text); | |||
| av_freep(&sub->rects[i]->ass); | |||
| av_freep(&sub->rects[i]); | |||
| @@ -29,7 +29,7 @@ | |||
| #include "libavutil/version.h" | |||
| #define LIBAVCODEC_VERSION_MAJOR 57 | |||
| #define LIBAVCODEC_VERSION_MINOR 8 | |||
| #define LIBAVCODEC_VERSION_MINOR 9 | |||
| #define LIBAVCODEC_VERSION_MICRO 100 | |||
| #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | |||
| @@ -188,5 +188,8 @@ | |||
| #ifndef FF_API_CONVERGENCE_DURATION | |||
| #define FF_API_CONVERGENCE_DURATION (LIBAVCODEC_VERSION_MAJOR < 59) | |||
| #endif | |||
| #ifndef FF_API_AVPICTURE | |||
| #define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59) | |||
| #endif | |||
| #endif /* AVCODEC_VERSION_H */ | |||
| @@ -57,6 +57,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |||
| int64_t packet_time = 0; | |||
| GetBitContext gb; | |||
| int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); | |||
| AVSubtitleRect *rect; | |||
| int j; | |||
| // check that at least header fits | |||
| 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, | |||
| sub->rects[0]->x = x; sub->rects[0]->y = y; | |||
| sub->rects[0]->w = w; sub->rects[0]->h = h; | |||
| sub->rects[0]->type = SUBTITLE_BITMAP; | |||
| sub->rects[0]->pict.linesize[0] = w; | |||
| sub->rects[0]->pict.data[0] = av_malloc(w * h); | |||
| sub->rects[0]->linesize[0] = w; | |||
| sub->rects[0]->data[0] = av_malloc(w * h); | |||
| sub->rects[0]->nb_colors = 4; | |||
| sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) { | |||
| av_freep(&sub->rects[0]->pict.data[1]); | |||
| av_freep(&sub->rects[0]->pict.data[0]); | |||
| sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE); | |||
| if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1]) { | |||
| av_freep(&sub->rects[0]->data[1]); | |||
| av_freep(&sub->rects[0]->data[0]); | |||
| av_freep(&sub->rects[0]); | |||
| av_freep(&sub->rects); | |||
| return AVERROR(ENOMEM); | |||
| @@ -119,23 +121,33 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |||
| // read palette | |||
| 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]->data[1])[i] = bytestream_get_be24(&buf); | |||
| 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; | |||
| ((uint32_t *)sub->rects[0]->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; | |||
| ((uint32_t *)sub->rects[0]->data[1])[i] |= *buf++ << 24; | |||
| } | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| rect = sub->rects[0]; | |||
| for (j = 0; j < 4; j++) { | |||
| rect->pict.data[j] = rect->data[j]; | |||
| rect->pict.linesize[j] = rect->linesize[j]; | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| // process RLE-compressed data | |||
| init_get_bits(&gb, buf, (buf_end - buf) * 8); | |||
| bitmap = sub->rects[0]->pict.data[0]; | |||
| bitmap = sub->rects[0]->data[0]; | |||
| for (y = 0; y < h; y++) { | |||
| // interlaced: do odd lines | |||
| if (y == (h + 1) / 2) bitmap = sub->rects[0]->pict.data[0] + w; | |||
| if (y == (h + 1) / 2) bitmap = sub->rects[0]->data[0] + w; | |||
| for (x = 0; x < w; ) { | |||
| int log2 = ff_log2_tab[show_bits(&gb, 8)]; | |||
| int run = get_bits(&gb, 14 - 4 * (log2 >> 1)); | |||
| @@ -131,8 +131,21 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, | |||
| if (h->num_rects != 1) | |||
| av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects); | |||
| #if FF_API_AVPICTURE | |||
| FF_DISABLE_DEPRECATION_WARNINGS | |||
| if (!h->rects[0]->data[0]) { | |||
| AVSubtitleRect *rect = h->rects[0]; | |||
| int j; | |||
| for (j = 0; j < 4; j++) { | |||
| rect->data[j] = rect->pict.data[j]; | |||
| rect->linesize[j] = rect->pict.linesize[j]; | |||
| } | |||
| } | |||
| FF_ENABLE_DEPRECATION_WARNINGS | |||
| #endif | |||
| // TODO: render text-based subtitles into bitmaps | |||
| if (!h->rects[0]->pict.data[0] || !h->rects[0]->pict.data[1]) { | |||
| if (!h->rects[0]->data[0] || !h->rects[0]->data[1]) { | |||
| av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n"); | |||
| return -1; | |||
| } | |||
| @@ -142,7 +155,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, | |||
| av_log(avctx, AV_LOG_WARNING, "No more than 4 subtitle colors supported (%d found.)\n", h->rects[0]->nb_colors); | |||
| // TODO: Palette swapping if color zero is not transparent | |||
| if (((uint32_t *)h->rects[0]->pict.data[1])[0] & 0xff000000) | |||
| if (((uint32_t *)h->rects[0]->data[1])[0] & 0xff000000) | |||
| av_log(avctx, AV_LOG_WARNING, "Color index 0 is not transparent. Transparency will be messed up.\n"); | |||
| if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) { | |||
| @@ -174,19 +187,19 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, | |||
| // Palette | |||
| for (i=0; i<4; i++) | |||
| bytestream_put_be24(&hdr, ((uint32_t *)h->rects[0]->pict.data[1])[i]); | |||
| bytestream_put_be24(&hdr, ((uint32_t *)h->rects[0]->data[1])[i]); | |||
| // Bitmap | |||
| // RLE buffer. Reserve 2 bytes for possible padding after the last row. | |||
| init_put_bits(&pb, hdr, bufsize - (hdr - buf) - 2); | |||
| if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0], | |||
| h->rects[0]->pict.linesize[0]*2, | |||
| if (xsub_encode_rle(&pb, h->rects[0]->data[0], | |||
| h->rects[0]->linesize[0] * 2, | |||
| h->rects[0]->w, (h->rects[0]->h + 1) >> 1)) | |||
| return -1; | |||
| bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field | |||
| if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0] + h->rects[0]->pict.linesize[0], | |||
| h->rects[0]->pict.linesize[0]*2, | |||
| if (xsub_encode_rle(&pb, h->rects[0]->data[0] + h->rects[0]->linesize[0], | |||
| h->rects[0]->linesize[0] * 2, | |||
| h->rects[0]->w, h->rects[0]->h >> 1)) | |||
| return -1; | |||