avcodec/xsubdec: Use dedicated pointer for AVSubtitleRect
Improves readability and slightly reduces codesize. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -52,6 +52,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
|
|||||||
const uint8_t *buf = avpkt->data;
|
const uint8_t *buf = avpkt->data;
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
AVSubtitle *sub = data;
|
AVSubtitle *sub = data;
|
||||||
|
AVSubtitleRect *rect;
|
||||||
const uint8_t *buf_end = buf + buf_size;
|
const uint8_t *buf_end = buf + buf_size;
|
||||||
uint8_t *bitmap;
|
uint8_t *bitmap;
|
||||||
int w, h, x, y, i, ret;
|
int w, h, x, y, i, ret;
|
||||||
@@ -100,40 +101,40 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
|
|||||||
if (!sub->rects)
|
if (!sub->rects)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
|
sub->rects[0] = rect = av_mallocz(sizeof(*sub->rects[0]));
|
||||||
if (!sub->rects[0])
|
if (!sub->rects[0])
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
sub->num_rects = 1;
|
sub->num_rects = 1;
|
||||||
sub->rects[0]->x = x; sub->rects[0]->y = y;
|
rect->x = x; rect->y = y;
|
||||||
sub->rects[0]->w = w; sub->rects[0]->h = h;
|
rect->w = w; rect->h = h;
|
||||||
sub->rects[0]->type = SUBTITLE_BITMAP;
|
rect->type = SUBTITLE_BITMAP;
|
||||||
sub->rects[0]->linesize[0] = w;
|
rect->linesize[0] = w;
|
||||||
sub->rects[0]->data[0] = av_malloc(w * h);
|
rect->data[0] = av_malloc(w * h);
|
||||||
sub->rects[0]->nb_colors = 4;
|
rect->nb_colors = 4;
|
||||||
sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE);
|
rect->data[1] = av_mallocz(AVPALETTE_SIZE);
|
||||||
if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1])
|
if (!rect->data[0] || !rect->data[1])
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
// read palette
|
// read palette
|
||||||
for (i = 0; i < sub->rects[0]->nb_colors; i++)
|
for (i = 0; i < rect->nb_colors; i++)
|
||||||
((uint32_t*)sub->rects[0]->data[1])[i] = bytestream_get_be24(&buf);
|
((uint32_t*)rect->data[1])[i] = bytestream_get_be24(&buf);
|
||||||
|
|
||||||
if (!has_alpha) {
|
if (!has_alpha) {
|
||||||
// make all except background (first entry) non-transparent
|
// make all except background (first entry) non-transparent
|
||||||
for (i = 1; i < sub->rects[0]->nb_colors; i++)
|
for (i = 1; i < rect->nb_colors; i++)
|
||||||
((uint32_t *)sub->rects[0]->data[1])[i] |= 0xff000000;
|
((uint32_t *)rect->data[1])[i] |= 0xff000000;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < sub->rects[0]->nb_colors; i++)
|
for (i = 0; i < rect->nb_colors; i++)
|
||||||
((uint32_t *)sub->rects[0]->data[1])[i] |= (unsigned)*buf++ << 24;
|
((uint32_t *)rect->data[1])[i] |= (unsigned)*buf++ << 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process RLE-compressed data
|
// process RLE-compressed data
|
||||||
if ((ret = init_get_bits8(&gb, buf, buf_end - buf)) < 0)
|
if ((ret = init_get_bits8(&gb, buf, buf_end - buf)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
bitmap = sub->rects[0]->data[0];
|
bitmap = rect->data[0];
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
// interlaced: do odd lines
|
// interlaced: do odd lines
|
||||||
if (y == (h + 1) / 2) bitmap = sub->rects[0]->data[0] + w;
|
if (y == (h + 1) / 2) bitmap = rect->data[0] + w;
|
||||||
for (x = 0; x < w; ) {
|
for (x = 0; x < w; ) {
|
||||||
int log2 = ff_log2_tab[show_bits(&gb, 8)];
|
int log2 = ff_log2_tab[show_bits(&gb, 8)];
|
||||||
int run = get_bits(&gb, 14 - 4 * (log2 >> 1));
|
int run = get_bits(&gb, 14 - 4 * (log2 >> 1));
|
||||||
|
Reference in New Issue
Block a user