[FFmpeg-cvslog] avcodec/mjpegenc_huffman: Make ff_mjpegenc_huffman_compute_bits() static

Andreas Rheinhardt git at videolan.org
Wed Apr 9 15:03:14 EEST 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed Apr  2 12:19:45 2025 +0200| [7ad16a44100137d3ad9f3e4d831bb646704ca066] | committer: Andreas Rheinhardt

avcodec/mjpegenc_huffman: Make ff_mjpegenc_huffman_compute_bits() static

Only used here and in a test tool.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7ad16a44100137d3ad9f3e4d831bb646704ca066
---

 libavcodec/mjpegenc_huffman.c       | 31 +++++++++++++++++++++++++++++--
 libavcodec/mjpegenc_huffman.h       | 29 -----------------------------
 libavcodec/tests/mjpegenc_huffman.c | 18 +++++++++---------
 3 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/libavcodec/mjpegenc_huffman.c b/libavcodec/mjpegenc_huffman.c
index 9bfcb7e785..898db7d060 100644
--- a/libavcodec/mjpegenc_huffman.c
+++ b/libavcodec/mjpegenc_huffman.c
@@ -25,6 +25,32 @@
 #include "libavutil/qsort.h"
 #include "mjpegenc_huffman.h"
 
+/**
+ * Used to assign a occurrence count or "probability" to an input value
+ */
+typedef struct PTable {
+    int value;  ///< input value
+    int prob;   ///< number of occurences of this value in input
+} PTable;
+
+/**
+ * Used to store intermediate lists in the package merge algorithm
+ */
+typedef struct PackageMergerList {
+    int nitems;             ///< number of items in the list and probability      ex. 4
+    int item_idx[515];      ///< index range for each item in items                   0, 2, 5, 9, 13
+    int probability[514];   ///< probability of each item                             3, 8, 18, 46
+    int items[257 * 16];    ///< chain of all individual values that make up items    A, B, A, B, C, A, B, C, D, C, D, D, E
+} PackageMergerList;
+
+/**
+ * Used to store optimal huffman encoding results
+ */
+typedef struct HuffTable {
+    int code;       ///< code is the input value
+    int length;     ///< length of the encoding
+} HuffTable;
+
 /**
  * Comparison function for two PTables by prob
  *
@@ -74,7 +100,8 @@ static int compare_by_length(const void *a, const void *b)
  * @param size       size of the prob_table array
  * @param max_length max length of an encoding
  */
-void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts, int size, int max_length)
+static void mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
+                                          int size, int max_length)
 {
     PackageMergerList list_a, list_b, *to = &list_a, *from = &list_b, *temp;
 
@@ -178,7 +205,7 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
     }
     val_counts[j].value = 256;
     val_counts[j].prob = 0;
-    ff_mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
+    mjpegenc_huffman_compute_bits(val_counts, distincts, nval + 1, 16);
     AV_QSORT(distincts, nval, HuffTable, compare_by_length);
 
     memset(bits, 0, sizeof(bits[0]) * 17);
diff --git a/libavcodec/mjpegenc_huffman.h b/libavcodec/mjpegenc_huffman.h
index 5fe65504e4..8822e468aa 100644
--- a/libavcodec/mjpegenc_huffman.h
+++ b/libavcodec/mjpegenc_huffman.h
@@ -44,33 +44,4 @@ void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
                                    uint8_t bits[17], uint8_t val[],
                                    int max_nval);
 
-
-/**
- * Used to assign a occurrence count or "probability" to an input value
- */
-typedef struct PTable {
-    int value;  ///< input value
-    int prob;   ///< number of occurences of this value in input
-} PTable;
-
-/**
- * Used to store intermediate lists in the package merge algorithm
- */
-typedef struct PackageMergerList {
-    int nitems;             ///< number of items in the list and probability      ex. 4
-    int item_idx[515];      ///< index range for each item in items                   0, 2, 5, 9, 13
-    int probability[514];   ///< probability of each item                             3, 8, 18, 46
-    int items[257 * 16];    ///< chain of all individual values that make up items    A, B, A, B, C, A, B, C, D, C, D, D, E
-} PackageMergerList;
-
-/**
- * Used to store optimal huffman encoding results
- */
-typedef struct HuffTable {
-    int code;       ///< code is the input value
-    int length;     ///< length of the encoding
-} HuffTable;
-
-void ff_mjpegenc_huffman_compute_bits(PTable *prob_table, HuffTable *distincts,
-                                      int size, int max_length);
 #endif /* AVCODEC_MJPEGENC_HUFFMAN_H */
diff --git a/libavcodec/tests/mjpegenc_huffman.c b/libavcodec/tests/mjpegenc_huffman.c
index 2ed92d07d5..39ad10c454 100644
--- a/libavcodec/tests/mjpegenc_huffman.c
+++ b/libavcodec/tests/mjpegenc_huffman.c
@@ -23,12 +23,12 @@
  * Optimal Huffman Encoding tests.
  */
 
-#include "libavcodec/avcodec.h"
-#include <stdlib.h>
-#include "libavcodec/mjpegenc.h"
-#include "libavcodec/mjpegenc_huffman.h"
-#include "libavcodec/mjpegenc_common.h"
-#include "libavcodec/mpegvideo.h"
+#include <stdio.h>
+
+#include "libavutil/avassert.h"
+#include "libavutil/macros.h"
+
+#include "libavcodec/mjpegenc_huffman.c"
 
 // Validate the computed lengths satisfy the JPEG restrictions and is optimal.
 static int check_lengths(int L, int expected_length,
@@ -45,7 +45,7 @@ static int check_lengths(int L, int expected_length,
         val_counts[i] = (PTable){.value = i, .prob = probs[i]};
     }
 
-    ff_mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
+    mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
 
     for (i = 0; i < nprobs; i++) {
         // Find the value's prob and length
@@ -137,8 +137,8 @@ int main(int argc, char **argv)
 
     // Build optimal huffman tree using an internal function, to allow for
     // smaller-than-normal test cases. This mutates val_counts by sorting.
-    ff_mjpegenc_huffman_compute_bits(val_counts, distincts,
-                                     FF_ARRAY_ELEMS(distincts), 3);
+    mjpegenc_huffman_compute_bits(val_counts, distincts,
+                                  FF_ARRAY_ELEMS(distincts), 3);
 
     for (i = 0; i < FF_ARRAY_ELEMS(distincts); i++) {
         if (distincts[i].code != expected[i].code ||



More information about the ffmpeg-cvslog mailing list