diff mbox series

[FFmpeg-devel,13/17] avcodec/rl: Add analogue for ff_rl_init() without RLTable

Message ID AS8P250MB07445BE6F007BF611567DB908F2F9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 0486f0f5d25099f4fce2638cd0388acae2a7afa1
Headers show
Series [FFmpeg-devel,01/17] avcodec/mpeg12dec: Remove redundant function call | expand

Commit Message

Andreas Rheinhardt Oct. 23, 2022, 7:36 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/rl.c | 17 +++++++++++++++++
 libavcodec/rl.h | 10 ++++++++++
 2 files changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/rl.c b/libavcodec/rl.c
index 645a5362f7..3f8271d37e 100644
--- a/libavcodec/rl.c
+++ b/libavcodec/rl.c
@@ -24,6 +24,23 @@ 
 
 #include "rl.h"
 
+av_cold void ff_rl_init_level_run(uint8_t max_level[MAX_LEVEL + 1],
+                                  uint8_t index_run[MAX_RUN + 1],
+                                  const uint8_t table_run[/* n */],
+                                  const uint8_t table_level[/* n*/],
+                                  int n)
+{
+    memset(index_run, n, MAX_RUN + 1);
+    for (int i = 0; i < n; i++) {
+        int run   = table_run[i];
+        int level = table_level[i];
+        if (index_run[run] == n)
+            index_run[run] = i;
+        if (level > max_level[run])
+            max_level[run] = level;
+    }
+}
+
 av_cold void ff_rl_init(RLTable *rl,
                         uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
 {
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 07e3da5003..4380fda272 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -48,6 +48,16 @@  typedef struct RLTable {
     RL_VLC_ELEM *rl_vlc[32];       ///< decoding only
 } RLTable;
 
+/**
+ * Initialize max_level and index_run from table_run and table_level;
+ * this is equivalent to initializing RLTable.max_level[0] and
+ * RLTable.index_run[0] with ff_rl_init().
+ */
+void ff_rl_init_level_run(uint8_t max_level[MAX_LEVEL + 1],
+                          uint8_t index_run[MAX_RUN + 1],
+                          const uint8_t table_run[/* n */],
+                          const uint8_t table_level[/* n*/], int n);
+
 /**
  * Initialize index_run, max_level and max_run from n, last, table_vlc,
  * table_run and table_level.