]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/movtextdec: Simplify finding default font
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 17 Oct 2020 11:33:07 +0000 (13:33 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 19 Oct 2020 02:58:30 +0000 (04:58 +0200)
There is no need to walk through the list of fonts twice.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/movtextdec.c

index e46c932c2087510e807ac48f794b5dd9bae5b922..974118c4c1271cd89db1c8ddc283e12abf48a2e7 100644 (file)
@@ -145,7 +145,7 @@ static void mov_text_cleanup_ftab(MovTextContext *m)
 static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
 {
     uint8_t *tx3g_ptr = avctx->extradata;
-    int i, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL;
+    int i, j = -1, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL;
     int8_t v_align, h_align;
     unsigned ftab_entries;
     StyleBox s_default;
@@ -230,6 +230,8 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
 
     for (i = 0; i < m->ftab_entries; i++) {
         m->ftab[i].fontID = AV_RB16(tx3g_ptr);
+        if (m->ftab[i].fontID == m->d.fontID)
+            j = i;
         tx3g_ptr += 2;
         font_length = *tx3g_ptr++;
 
@@ -247,10 +249,8 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
         m->ftab[i].font[font_length] = '\0';
         tx3g_ptr = tx3g_ptr + font_length;
     }
-    for (i = 0; i < m->ftab_entries; i++) {
-        if (m->d.fontID == m->ftab[i].fontID)
-            m->d.font = m->ftab[i].font;
-    }
+    if (j >= 0)
+        m->d.font = m->ftab[j].font;
     return 0;
 }