Use the new fields directly instead of the ones from AVPicture.
This removes a layer of indirection which serves no pratical purpose
whatsoever, and will help in removing AVPicture structure completely
later.
Every subtitle encoder/decoder seamlessly points to the new arrays,
so it is possible to deprecate AVSubtitleRect.pict.
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
width2 = ((dstw + 1) >> 1) + (dstx & ~dstw & 1);
skip2 = dstx >> 1;
wrap = dst->linesize[0];
- wrap3 = rect->pict.linesize[0];
- p = rect->pict.data[0];
- pal = (const uint32_t *)rect->pict.data[1]; /* Now in YCrCb! */
+ wrap3 = rect->linesize[0];
+ p = rect->data[0];
+ pal = (const uint32_t *)rect->data[1]; /* Now in YCrCb! */
if (dsty & 1) {
lum += dstx;
{
for (j = 0; j < sp->sub.rects[i]->nb_colors; j++)
{
- RGBA_IN(r, g, b, a, (uint32_t*)sp->sub.rects[i]->pict.data[1] + j);
+ RGBA_IN(r, g, b, a, (uint32_t *)sp->sub.rects[i]->data[1] + j);
y = RGB_TO_Y_CCIR(r, g, b);
u = RGB_TO_U_CCIR(r, g, b, 0);
v = RGB_TO_V_CCIR(r, g, b, 0);
- YUVA_OUT((uint32_t*)sp->sub.rects[i]->pict.data[1] + j, y, u, v, a);
+ YUVA_OUT((uint32_t *)sp->sub.rects[i]->data[1] + j, y, u, v, a);
}
}
API changes, most recent first:
+2015-xx-xx - xxxxxxx - 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-xx-xx - xxxxxxx - lavc 57.0.0 - qsv.h
Add an API for allocating opaque surfaces.
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 where 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
*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;
dvb_encode_rle = dvb_encode_rle4;
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);
i = 0;
for (display = ctx->display_list; display; display = display->next) {
+ int j;
region = get_region(ctx, display->region_id);
rect = sub->rects[i];
rect->h = region->height;
rect->nb_colors = 16;
rect->type = SUBTITLE_BITMAP;
- rect->pict.linesize[0] = region->width;
+ rect->linesize[0] = region->width;
clut = get_clut(ctx, region->clut);
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]) {
av_free(sub->rects);
return AVERROR(ENOMEM);
}
- 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]) {
- av_free(rect->pict.data[1]);
+ rect->data[0] = av_malloc(region->buf_size);
+ if (!rect->data[0]) {
+ av_free(rect->data[1]);
av_free(sub->rects);
return AVERROR(ENOMEM);
}
- memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
+ memcpy(rect->data[0], region->pbuf, region->buf_size);
+
+#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++;
}
if (h < 0)
h = 0;
if (w > 0 && h > 0) {
+ int j;
+ AVSubtitleRect *rect;
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);
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;
decode_rle(bitmap, w * 2, w, (h + 1) / 2,
buf, offset1, buf_size, is_8bit);
decode_rle(bitmap + w, w * 2, w, h / 2,
buf, offset2, buf_size, is_8bit);
- 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 == 0)
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],
+ (uint32_t *)sub_header->rects[0]->data[1],
colormap, alpha, 0xffff00);
}
sub_header->rects[0]->x = x1;
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;
+
+#if FF_API_AVPICTURE
+FF_DISABLE_DEPRECATION_WARNINGS
+ rect = sub_header->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
}
}
if (next_cmd_pos == cmd_pos)
fail:
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);
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;
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;
ff_dlog(NULL, "start=%d ms end =%d ms\n",
sub->start_display_time,
sub->end_display_time);
- ppm_save("/tmp/a.ppm", sub->rects[0]->pict.data[0],
- sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->pict.data[1]);
+ ppm_save("/tmp/a.ppm", sub->rects[0]->data[0],
+ sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->data[1]);
#endif
*data_size = 1;
hist[i] = 0;
cmap[i] = 0;
}
- for (object_id = 0; object_id < rects; object_id++)
+ for (object_id = 0; object_id < rects; object_id++) {
+#if FF_API_AVPICTURE
+FF_DISABLE_DEPRECATION_WARNINGS
+ if (!h->rects[object_id]->data[0]) {
+ AVSubtitleRect *rect = h->rects[object_id];
+ 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
+
for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) {
- color = h->rects[object_id]->pict.data[0][i];
+ color = h->rects[object_id]->data[0][i];
// only count non-transparent pixels
- alpha = ((uint32_t*)h->rects[object_id]->pict.data[1])[color] >> 24;
+ alpha = ((uint32_t *)h->rects[object_id]->data[1])[color] >> 24;
hist[color] += alpha;
}
+ }
for (color=3;; --color) {
hmax = 0;
imax = 0;
av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
return -1;
}
- dvd_encode_rle(&q, h->rects[object_id]->pict.data[0],
+ dvd_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,
cmap);
offset2[object_id] = q - outbuf;
- dvd_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
+ dvd_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,
cmap);
rle_bitmap_end = buf + buf_size;
- rect->pict.data[0] = av_malloc(rect->w * rect->h);
+ rect->data[0] = av_malloc(rect->w * rect->h);
- if (!rect->pict.data[0])
+ if (!rect->data[0])
return AVERROR(ENOMEM);
pixel_count = 0;
}
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) {
/*
}
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]) {
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 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
if (object->rle) {
if (object->rle_remaining_len) {
}
/* 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);
}
- 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));
}
return 1;
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]);
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57
-#define LIBAVCODEC_VERSION_MINOR 4
+#define LIBAVCODEC_VERSION_MINOR 5
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
#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 */
int64_t packet_time = 0;
GetBitContext gb;
int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
+ AVSubtitleRect *rect;
+ int j;
memset(sub, 0, sizeof(*sub));
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);
// 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));
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;
}
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] & 0xff)
+ if (((uint32_t *)h->rects[0]->data[1])[0] & 0xff)
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)) {
// 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;