diff mbox series

[FFmpeg-devel,11/12] avcodec/xsubdec: Use dedicated pointer for AVSubtitleRect

Message ID AM7PR03MB66604063754638735E6A0D208F729@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 6e02ca35e574c344ccdb3be9fd8817af50efabd1
Headers show
Series [FFmpeg-devel,01/12] avcodec/h2645_parse: Remove H2645NAL.rbsp_buffer | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 11, 2021, 6:40 p.m. UTC
Improves readability and slightly reduces codesize.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/xsubdec.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
diff mbox series

Patch

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));