mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
Originally committed as revision 16416 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
ebc466bb5f
commit
25b4c651a3
4
ffmpeg.c
4
ffmpeg.c
@ -1401,8 +1401,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
|
||||
if (subtitle_to_free) {
|
||||
if (subtitle_to_free->rects != NULL) {
|
||||
for (i = 0; i < subtitle_to_free->num_rects; i++) {
|
||||
av_freep(&subtitle_to_free->rects[i]->bitmap);
|
||||
av_freep(&subtitle_to_free->rects[i]->rgba_palette);
|
||||
av_freep(&subtitle_to_free->rects[i]->pict.data[0]);
|
||||
av_freep(&subtitle_to_free->rects[i]->pict.data[1]);
|
||||
av_freep(&subtitle_to_free->rects[i]);
|
||||
}
|
||||
av_freep(&subtitle_to_free->rects);
|
||||
|
14
ffplay.c
14
ffplay.c
@ -452,9 +452,9 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw,
|
||||
width2 = (dstw + 1) >> 1;
|
||||
skip2 = dstx >> 1;
|
||||
wrap = dst->linesize[0];
|
||||
wrap3 = rect->linesize;
|
||||
p = rect->bitmap;
|
||||
pal = rect->rgba_palette; /* Now in YCrCb! */
|
||||
wrap3 = rect->pict.linesize[0];
|
||||
p = rect->pict.data[0];
|
||||
pal = (const uint32_t *)rect->pict.data[1]; /* Now in YCrCb! */
|
||||
|
||||
if (dsty & 1) {
|
||||
lum += dstx;
|
||||
@ -636,8 +636,8 @@ static void free_subpicture(SubPicture *sp)
|
||||
|
||||
for (i = 0; i < sp->sub.num_rects; i++)
|
||||
{
|
||||
av_freep(&sp->sub.rects[i]->bitmap);
|
||||
av_freep(&sp->sub.rects[i]->rgba_palette);
|
||||
av_freep(&sp->sub.rects[i]->pict.data[0]);
|
||||
av_freep(&sp->sub.rects[i]->pict.data[1]);
|
||||
av_freep(&sp->sub.rects[i]);
|
||||
}
|
||||
|
||||
@ -1438,11 +1438,11 @@ static int subtitle_thread(void *arg)
|
||||
{
|
||||
for (j = 0; j < sp->sub.rects[i]->nb_colors; j++)
|
||||
{
|
||||
RGBA_IN(r, g, b, a, sp->sub.rects[i]->rgba_palette + j);
|
||||
RGBA_IN(r, g, b, a, (uint32_t*)sp->sub.rects[i]->pict.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(sp->sub.rects[i]->rgba_palette + j, y, u, v, a);
|
||||
YUVA_OUT((uint32_t*)sp->sub.rects[i]->pict.data[1] + j, y, u, v, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2399,9 +2399,12 @@ typedef struct AVSubtitleRect {
|
||||
int w; ///< width of pict, undefined when pict is not set
|
||||
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
|
||||
int linesize;
|
||||
uint32_t *rgba_palette;
|
||||
uint8_t *bitmap;
|
||||
|
||||
/**
|
||||
* data+linesize for the bitmap of this subtitle.
|
||||
* can be set for text/ass as well once they where rendered
|
||||
*/
|
||||
AVPicture pict;
|
||||
} AVSubtitleRect;
|
||||
|
||||
typedef struct AVSubtitle {
|
||||
|
@ -262,10 +262,11 @@ 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;
|
||||
a = (h->rects[clut_id]->rgba_palette[i] >> 24) & 0xff;
|
||||
r = (h->rects[clut_id]->rgba_palette[i] >> 16) & 0xff;
|
||||
g = (h->rects[clut_id]->rgba_palette[i] >> 8) & 0xff;
|
||||
b = (h->rects[clut_id]->rgba_palette[i] >> 0) & 0xff;
|
||||
uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i];
|
||||
a = (x >> 24) & 0xff;
|
||||
r = (x >> 16) & 0xff;
|
||||
g = (x >> 8) & 0xff;
|
||||
b = (x >> 0) & 0xff;
|
||||
|
||||
*q++ = RGB_TO_Y_CCIR(r, g, b);
|
||||
*q++ = RGB_TO_V_CCIR(r, g, b, 0);
|
||||
@ -358,10 +359,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
|
||||
dvb_encode_rle = dvb_encode_rle4;
|
||||
|
||||
top_ptr = q;
|
||||
dvb_encode_rle(&q, h->rects[object_id]->bitmap, h->rects[object_id]->w * 2,
|
||||
dvb_encode_rle(&q, h->rects[object_id]->pict.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]->bitmap + h->rects[object_id]->w,
|
||||
dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
|
||||
h->rects[object_id]->w * 2, h->rects[object_id]->w,
|
||||
h->rects[object_id]->h >> 1);
|
||||
|
||||
|
@ -1305,7 +1305,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
|
||||
rect->w = region->width;
|
||||
rect->h = region->height;
|
||||
rect->nb_colors = 16;
|
||||
rect->linesize = region->width;
|
||||
rect->pict.linesize[0] = region->width;
|
||||
|
||||
clut = get_clut(ctx, region->clut);
|
||||
|
||||
@ -1325,11 +1325,11 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
|
||||
break;
|
||||
}
|
||||
|
||||
rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t));
|
||||
memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t));
|
||||
rect->pict.data[1] = av_malloc((1 << region->depth) * sizeof(uint32_t));
|
||||
memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
|
||||
|
||||
rect->bitmap = av_malloc(region->buf_size);
|
||||
memcpy(rect->bitmap, region->pbuf, region->buf_size);
|
||||
rect->pict.data[0] = av_malloc(region->buf_size);
|
||||
memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
@ -319,8 +319,8 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
|
||||
if (w > 0 && h > 0) {
|
||||
if (sub_header->rects != NULL) {
|
||||
for (i = 0; i < sub_header->num_rects; i++) {
|
||||
av_freep(&sub_header->rects[i]->bitmap);
|
||||
av_freep(&sub_header->rects[i]->rgba_palette);
|
||||
av_freep(&sub_header->rects[i]->pict.data[0]);
|
||||
av_freep(&sub_header->rects[i]->pict.data[1]);
|
||||
av_freep(&sub_header->rects[i]);
|
||||
}
|
||||
av_freep(&sub_header->rects);
|
||||
@ -331,7 +331,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
|
||||
sub_header->rects = av_mallocz(sizeof(*sub_header->rects));
|
||||
sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect));
|
||||
sub_header->num_rects = 1;
|
||||
sub_header->rects[0]->bitmap = bitmap;
|
||||
sub_header->rects[0]->pict.data[0] = bitmap;
|
||||
decode_rle(bitmap, w * 2, w, (h + 1) / 2,
|
||||
buf, offset1, buf_size, is_8bit);
|
||||
decode_rle(bitmap + w, w * 2, w, h / 2,
|
||||
@ -339,20 +339,20 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
|
||||
if (is_8bit) {
|
||||
if (yuv_palette == 0)
|
||||
goto fail;
|
||||
sub_header->rects[0]->rgba_palette = av_malloc(256 * 4);
|
||||
sub_header->rects[0]->pict.data[1] = av_malloc(256 * 4);
|
||||
sub_header->rects[0]->nb_colors = 256;
|
||||
yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0]->rgba_palette, 256);
|
||||
yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
|
||||
} else {
|
||||
sub_header->rects[0]->rgba_palette = av_malloc(4 * 4);
|
||||
sub_header->rects[0]->pict.data[1] = av_malloc(4 * 4);
|
||||
sub_header->rects[0]->nb_colors = 4;
|
||||
guess_palette(sub_header->rects[0]->rgba_palette,
|
||||
guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
|
||||
colormap, alpha, 0xffff00);
|
||||
}
|
||||
sub_header->rects[0]->x = x1;
|
||||
sub_header->rects[0]->y = y1;
|
||||
sub_header->rects[0]->w = w;
|
||||
sub_header->rects[0]->h = h;
|
||||
sub_header->rects[0]->linesize = w;
|
||||
sub_header->rects[0]->pict.linesize[0] = w;
|
||||
}
|
||||
}
|
||||
if (next_cmd_pos == cmd_pos)
|
||||
@ -364,8 +364,8 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
|
||||
fail:
|
||||
if (sub_header->rects != NULL) {
|
||||
for (i = 0; i < sub_header->num_rects; i++) {
|
||||
av_freep(&sub_header->rects[i]->bitmap);
|
||||
av_freep(&sub_header->rects[i]->rgba_palette);
|
||||
av_freep(&sub_header->rects[i]->pict.data[0]);
|
||||
av_freep(&sub_header->rects[i]->pict.data[1]);
|
||||
av_freep(&sub_header->rects[i]);
|
||||
}
|
||||
av_freep(&sub_header->rects);
|
||||
@ -398,29 +398,29 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s)
|
||||
|
||||
memset(transp_color, 0, 256);
|
||||
for(i = 0; i < s->rects[0]->nb_colors; i++) {
|
||||
if ((s->rects[0]->rgba_palette[i] >> 24) == 0)
|
||||
if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)
|
||||
transp_color[i] = 1;
|
||||
}
|
||||
y1 = 0;
|
||||
while (y1 < s->rects[0]->h && is_transp(s->rects[0]->bitmap + y1 * s->rects[0]->linesize,
|
||||
while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],
|
||||
1, s->rects[0]->w, transp_color))
|
||||
y1++;
|
||||
if (y1 == s->rects[0]->h) {
|
||||
av_freep(&s->rects[0]->bitmap);
|
||||
av_freep(&s->rects[0]->pict.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]->bitmap + y2 * s->rects[0]->linesize, 1,
|
||||
while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,
|
||||
s->rects[0]->w, transp_color))
|
||||
y2--;
|
||||
x1 = 0;
|
||||
while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->bitmap + x1, s->rects[0]->linesize,
|
||||
while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],
|
||||
s->rects[0]->h, transp_color))
|
||||
x1++;
|
||||
x2 = s->rects[0]->w - 1;
|
||||
while (x2 > 0 && is_transp(s->rects[0]->bitmap + x2, s->rects[0]->linesize, s->rects[0]->h,
|
||||
while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,
|
||||
transp_color))
|
||||
x2--;
|
||||
w = x2 - x1 + 1;
|
||||
@ -429,11 +429,11 @@ 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]->bitmap + x1 + (y1 + y) * s->rects[0]->linesize, w);
|
||||
memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);
|
||||
}
|
||||
av_freep(&s->rects[0]->bitmap);
|
||||
s->rects[0]->bitmap = bitmap;
|
||||
s->rects[0]->linesize = w;
|
||||
av_freep(&s->rects[0]->pict.data[0]);
|
||||
s->rects[0]->pict.data[0] = bitmap;
|
||||
s->rects[0]->pict.linesize[0] = w;
|
||||
s->rects[0]->w = w;
|
||||
s->rects[0]->h = h;
|
||||
s->rects[0]->x += x1;
|
||||
@ -494,8 +494,8 @@ static int dvdsub_decode(AVCodecContext *avctx,
|
||||
av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n",
|
||||
sub->start_display_time,
|
||||
sub->end_display_time);
|
||||
ppm_save("/tmp/a.ppm", sub->rects[0]->bitmap,
|
||||
sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->rgba_palette);
|
||||
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]);
|
||||
#endif
|
||||
|
||||
*data_size = 1;
|
||||
|
@ -109,9 +109,9 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
|
||||
}
|
||||
for (object_id = 0; object_id < rects; object_id++)
|
||||
for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) {
|
||||
color = h->rects[object_id]->bitmap[i];
|
||||
color = h->rects[object_id]->pict.data[0][i];
|
||||
// only count non-transparent pixels
|
||||
alpha = h->rects[object_id]->rgba_palette[color] >> 24;
|
||||
alpha = ((uint32_t*)h->rects[object_id]->pict.data[1])[color] >> 24;
|
||||
hist[color] += alpha;
|
||||
}
|
||||
for (color=3;; --color) {
|
||||
@ -143,12 +143,12 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
|
||||
av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
|
||||
return -1;
|
||||
}
|
||||
dvd_encode_rle(&q, h->rects[object_id]->bitmap,
|
||||
dvd_encode_rle(&q, h->rects[object_id]->pict.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]->bitmap + h->rects[object_id]->w,
|
||||
dvd_encode_rle(&q, h->rects[object_id]->pict.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);
|
||||
|
@ -84,28 +84,28 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
|
||||
sub->num_rects = 1;
|
||||
}
|
||||
av_freep(&sub->rects[0]->bitmap);
|
||||
av_freep(&sub->rects[0]->pict.data[0]);
|
||||
sub->rects[0]->x = x; sub->rects[0]->y = y;
|
||||
sub->rects[0]->w = w; sub->rects[0]->h = h;
|
||||
sub->rects[0]->linesize = w;
|
||||
sub->rects[0]->bitmap = av_malloc(w * h);
|
||||
sub->rects[0]->pict.linesize[0] = w;
|
||||
sub->rects[0]->pict.data[0] = av_malloc(w * h);
|
||||
sub->rects[0]->nb_colors = 4;
|
||||
sub->rects[0]->rgba_palette = av_malloc(sub->rects[0]->nb_colors * 4);
|
||||
sub->rects[0]->pict.data[1] = av_malloc(sub->rects[0]->nb_colors * 4);
|
||||
|
||||
// read palette
|
||||
for (i = 0; i < sub->rects[0]->nb_colors; i++)
|
||||
sub->rects[0]->rgba_palette[i] = bytestream_get_be24(&buf);
|
||||
((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);
|
||||
// make all except background (first entry) non-transparent
|
||||
for (i = 1; i < sub->rects[0]->nb_colors; i++)
|
||||
sub->rects[0]->rgba_palette[i] |= 0xff000000;
|
||||
((uint32_t*)sub->rects[0]->pict.data[1])[i] |= 0xff000000;
|
||||
|
||||
// process RLE-compressed data
|
||||
rlelen = FFMIN(rlelen, buf_end - buf);
|
||||
init_get_bits(&gb, buf, rlelen * 8);
|
||||
bitmap = sub->rects[0]->bitmap;
|
||||
bitmap = sub->rects[0]->pict.data[0];
|
||||
for (y = 0; y < h; y++) {
|
||||
// interlaced: do odd lines
|
||||
if (y == (h + 1) / 2) bitmap = sub->rects[0]->bitmap + w;
|
||||
if (y == (h + 1) / 2) bitmap = sub->rects[0]->pict.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));
|
||||
|
Loading…
Reference in New Issue
Block a user