summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-10 22:54:45 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-16 02:37:26 +0100
commit6e02ca35e574c344ccdb3be9fd8817af50efabd1 (patch)
treea7d79657dee24488bfc46e67d5d6c507b5f5f384
parent077167fab9067c606c374e0fd26930f78465387b (diff)
avcodec/xsubdec: Use dedicated pointer for AVSubtitleRect
Improves readability and slightly reduces codesize. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/xsubdec.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index b483699d0a..85cd7d1c20 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -52,6 +52,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AVSubtitle *sub = data;
+ AVSubtitleRect *rect;
const uint8_t *buf_end = buf + buf_size;
uint8_t *bitmap;
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)
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])
return AVERROR(ENOMEM);
sub->num_rects = 1;
- 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]->linesize[0] = w;
- sub->rects[0]->data[0] = av_malloc(w * h);
- sub->rects[0]->nb_colors = 4;
- sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE);
- if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1])
+ rect->x = x; rect->y = y;
+ rect->w = w; rect->h = h;
+ rect->type = SUBTITLE_BITMAP;
+ rect->linesize[0] = w;
+ rect->data[0] = av_malloc(w * h);
+ rect->nb_colors = 4;
+ rect->data[1] = av_mallocz(AVPALETTE_SIZE);
+ if (!rect->data[0] || !rect->data[1])
return AVERROR(ENOMEM);
// read palette
- for (i = 0; i < sub->rects[0]->nb_colors; i++)
- ((uint32_t*)sub->rects[0]->data[1])[i] = bytestream_get_be24(&buf);
+ for (i = 0; i < rect->nb_colors; i++)
+ ((uint32_t*)rect->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]->data[1])[i] |= 0xff000000;
+ for (i = 1; i < rect->nb_colors; i++)
+ ((uint32_t *)rect->data[1])[i] |= 0xff000000;
} else {
- for (i = 0; i < sub->rects[0]->nb_colors; i++)
- ((uint32_t *)sub->rects[0]->data[1])[i] |= (unsigned)*buf++ << 24;
+ for (i = 0; i < rect->nb_colors; i++)
+ ((uint32_t *)rect->data[1])[i] |= (unsigned)*buf++ << 24;
}
// process RLE-compressed data
if ((ret = init_get_bits8(&gb, buf, buf_end - buf)) < 0)
return ret;
- bitmap = sub->rects[0]->data[0];
+ bitmap = rect->data[0];
for (y = 0; y < h; y++) {
// 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; ) {
int log2 = ff_log2_tab[show_bits(&gb, 8)];
int run = get_bits(&gb, 14 - 4 * (log2 >> 1));